Re: bug in 9.2.2 ? subquery accepts wrong column name : upd

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: bug in 9.2.2 ? subquery accepts wrong column name : upd
Date: 2013-03-14 16:17:46
Message-ID: 17320.1363277866@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com> writes:
> dynacom=# SELECT DISTINCT ON (qry.setid) qry.setid, qry.arragg[1:2] FROM
> (select distinct sst.setid,(array_agg(vsl.name) OVER (PARTITION BY sst.setid ORDER BY character_length(vsl.name))) as arragg
> FROM sissets sst, vessels vsl WHERE vsl.id=sst.vslid ORDER BY sst.setid) as qry
> WHERE array_length(qry.arragg,1)>1 AND qry.setid IN (SELECT setid from sis_oper_cons) ORDER BY qry.setid,array_length(qry.arragg,1);
> [ works ]

> however, there is not column setid in sis_oper_cons,

If not, that's a perfectly legal outer reference to qry.setid.

Probably not one of SQL's better design features, since it confuses
people regularly; but it's required by spec to work like that.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message JORGE MALDONADO 2013-03-14 22:25:48 UPDATE query with variable number of OR conditions in WHERE
Previous Message Achilleas Mantzios 2013-03-14 15:29:07 bug in 9.2.2 ? subquery accepts wrong column name : upd