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-18 17:10:24
Message-ID: 20090518171024.GL22221@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, May 18, 2009 at 06:49:30AM -0700, Scara Maccai wrote:
> why column "acoltest" is not found by the subselect in this select:

The "acoltest" identifier is only visible from outside the query, not
within its defining query or any of its sub-queries. If you're trying
to solve a problem like the example, it would probably be easiest to
swap the inner and outer queries around, i.e. something like:

SELECT acoltest, MAX(b.t)
FROM (
SELECT acol + 100 as acoltest
FROM mytab2
GROUP BY 1) a LEFT JOIN mytab b ON a.acoltest = b.anothercol
GROUP BY acoltest;

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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2009-05-18 17:15:28 Re: Need help
Previous Message Sam Mason 2009-05-18 16:57:45 Re: Excel and pg