Unix Technical Forum

Reusing columns in SELECT list

This is a discussion on Reusing columns in SELECT list within the pgsql Novice forums, part of the PostgreSQL category; --> Hello all. Is there a way to reuse in the SELECT list columns defined earlier in it ? With ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:35 PM
Andre Majorel
 
Posts: n/a
Default Reusing columns in SELECT list

Hello all.

Is there a way to reuse in the SELECT list columns defined earlier
in it ? With PostgreSQL 8.0, I couldn't manage to do it :

=> CREATE table a (x int);
CREATE TABLE
=> CREATE table b (y int);
CREATE TABLE
=> SELECT x * y AS xy, xy + xy AS twoxy FROM a, b;
ERROR: column "xy" does not exist

--
André Majorel <URL:http://www.teaser.fr/~amajorel/>
Do not use this account for regular correspondence.
See the URL above for contact information.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:35 PM
Tom Lane
 
Posts: n/a
Default Re: Reusing columns in SELECT list

Andre Majorel <aym-lqsgp@teaser.fr> writes:
> Is there a way to reuse in the SELECT list columns defined earlier
> in it ?


No.

You can use multiple levels of select:

select xy, xy + xy from (select x * y as xy from a,b) ss;

but this is not likely to save any computation, just typing.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:19 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com