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

Simple SQL

P: n/a
Is it possible to do something like:

select 1 as a, a*a;

in postgres?

Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Is it possible to do something like:

select 1 as a, a*a;

in postgres?


Perhaps on this way:

SELECT a, a*a FROM
(SELECT 1 AS a);

Greetings....
Nov 12 '05 #2

P: n/a
Not

SELECT 1 as a, a*2;
ERROR: column "a" does not exist

Regards
Pavel
On Tue, 21 Oct 2003, Bob Messenger wrote:
Is it possible to do something like:

select 1 as a, a*a;

in postgres?
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #3

P: n/a
On Fri, Oct 24, 2003 at 07:25:44AM +0200, Pavel Stehule wrote:
Not

SELECT 1 as a, a*2;
ERROR: column "a" does not exist
But you can try

SELECT a, a*a FROM (select 1 as a);
On Tue, 21 Oct 2003, Bob Messenger wrote:
Is it possible to do something like:

select 1 as a, a*a;

in postgres?


--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Hay que recordar que la existencia en el cosmos, y particularmente la
elaboración de civilizaciones dentre de él no son, por desgracia,
nada idílicas" (Ijon Tichy)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #4

P: n/a
Alvaro Herrera wrote:
On Fri, Oct 24, 2003 at 07:25:44AM +0200, Pavel Stehule wrote:
Not

SELECT 1 as a, a*2;
ERROR: column "a" does not exist

But you can try

SELECT a, a*a FROM (select 1 as a);

On Tue, 21 Oct 2003, Bob Messenger wrote:

Is it possible to do something like:

select 1 as a, a*a;

in postgres?



alien=# SELECT a, a*a FROM (select 1 as a);
ERROR: sub-SELECT in FROM must have an alias
For example, FROM (SELECT ...) [AS] foo

Thanks for idea though. It led me to this:

alien=# SELECT a, a*a FROM (SELECT 2 AS a) AS a;
a | ?column?
---+----------
2 | 4
(1 row)

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.