Re: referring to calculated column in sub select

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: referring to calculated column in sub select
Date: 2009-05-19 09:27:29
Message-ID: 20090519092729.GQ22221@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 19, 2009 at 12:04:28AM -0700, Scara Maccai wrote:
> Using Mysql the query works, so I expected it to be somehow "standard"
> (I know, Mysql sometimes allows much more than the standard...)

No, as far as I know the standard explicitly says that the MySQL
behaviour is incorrect.

> Does this has something to do with Support LATERAL subqueries" in the
> to do list?

No, a lateral sub-query would be something like the following:

SELECT f.a, b.b
FROM foo a, getrows(a.a) b(b);

I.e. in order to execute the "getrows" function you need to have values
out of "foo" first. You can do this in some specific instances at the
moment in PG, but not in general.

> It's a very shame it's not supported...

another rewrite of your query would be to have a sub-select:

SELECT acoltest,
(SELECT max(t) FROM mytab WHERE anothercol=acoltest) as col2
FROM (SELECT somet, acol+100 AS acoltest FROM mytab2)
GROUP BY somet;

Hope that helps!

--
Sam http://samason.me.uk/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2009-05-19 09:30:22 Re: INTERVAL SECOND limited to 59 seconds?
Previous Message Sebastien FLAESCH 2009-05-19 09:17:13 Re: INTERVAL SECOND limited to 59 seconds?