Search Postgresql Archives

Re: why isn't this subquery wrong?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



jonathan vanasco <postgres@xxxxxxxx> writes:
> Can anyone explain to me why the following is valid (running 9.6) ?

> SELECT foo_id
> 	FROM example_a__data
> 	WHERE foo_id IN (SELECT bar_id FROM example_a__rollup)
> 	;

Per the SQL standard, bar_id is interpreted as an "outer reference"
to example_a__data.bar_id.  This trips people up all the time, but
(a) it's required by spec and (b) there are cases where it's really
hard to do what you want without an outer reference.

Cautious SQL programmers qualify all references inside sub-selects
to avoid getting caught by this accidentally.

			regards, tom lane


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux