Re: undocumented feature or bug in subquery : psql (PostgreSQL) 9.4.6 on SLES12 SP1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: otter117(at)yahoo(dot)de
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: undocumented feature or bug in subquery : psql (PostgreSQL) 9.4.6 on SLES12 SP1
Date: 2016-08-26 13:07:14
Message-ID: 26546.1472216834@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

otter117(at)yahoo(dot)de writes:
> 2 tables a and b
> Table &quot;public.a&quot;
> Column | Type | Modifiers
> -----------------+--------------------------+---------------
> foo | integer | not null
> bar | integer | not null

> Table &quot;public.b&quot;
> Column | Type | Modifiers
> -----------------+--------------------------+---------------
> bar | integer | not null

> No error when executing this statement even though table b does not contain
> column foo
> SELECT foo,bar FROM a WHERE foo=1 AND bar NOT IN (SELECT bar FROM b WHERE
> bar > 2 AND foo=2)

No, but table a does, and that's a legal outer reference per the SQL
standard. This is neither a bug nor undocumented.

> Do I need to qualify all columns in the subquery or is this a bug is psql
> 9.4.6?

It's often wise to qualify column references in multi-table queries
(subqueries or not) to ensure they are referencing what you think
they're referencing.

regards, tom lane

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message paul.alsemgeest 2016-08-31 07:52:56 How to backup
Previous Message Bruce Momjian 2016-08-25 22:41:43 Re: does md5 really help against sniffing?