By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,835 Members | 2,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,835 IT Pros & Developers. It's quick & easy.

reusing column labels in select

P: n/a
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
Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 <rv*******@gmail.com> wrote:
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 ma*******@postgresql.org


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

Nov 23 '05 #2

P: n/a
* ryan <rv*******@gmail.com> [2004-10-16 11:18:48 -0700]:
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

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.