dbTalk Databases Forums  

reusing column labels in select

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss reusing column labels in select in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ryan
 
Posts: n/a

Default reusing column labels in select - 10-16-2004 , 01:18 PM






Hello,

Is there any way to reuse a column label in a select list like this:

SELECT 1 + 1 AS a, a + 1 AS b;

I vaguely remember being able to do something like this in oracle. Any
ideas? Thanks!

~RvR

Reply With Quote
  #2  
Old   
Kevin Barnard
 
Posts: n/a

Default Re: reusing column labels in select - 10-19-2004 , 05:16 PM






There might be a better way then this but this works

SELECT a, a+1 as b from (SELECT 1+1 as a) as ab;


On 16 Oct 2004 11:18:48 -0700, ryan <rvanroode (AT) gmail (DOT) com> wrote:
Quote:
Hello,

Is there any way to reuse a column label in a select list like this:

SELECT 1 + 1 AS a, a + 1 AS b;

I vaguely remember being able to do something like this in oracle. Any
ideas? Thanks!

~RvR

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org

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



Reply With Quote
  #3  
Old   
Steven Klassen
 
Posts: n/a

Default Re: reusing column labels in select - 10-19-2004 , 05:18 PM



* ryan <rvanroode (AT) gmail (DOT) com> [2004-10-16 11:18:48 -0700]:

Quote:
Is there any way to reuse a column label in a select list like this:

SELECT 1 + 1 AS a, a + 1 AS b;

I vaguely remember being able to do something like this in oracle. Any
ideas? Thanks!
You could nest them...

xinu=> select (1 + 1) + 1 as answer;
answer
--------
3
(1 row)

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.