Re: BUG #17754: Subquery IN clause returns row matches where subquery is invalid

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: gurmokh(dot)sangha(at)starlingbank(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17754: Subquery IN clause returns row matches where subquery is invalid
Date: 2023-01-19 19:42:48
Message-ID: 4191911.1674157368@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> A subquery that has an incorrect column name, that happens to match a column
> name in the outer query evaluates as true for all rows in the outer query.

Such a reference is called an "outer reference", and it's a required
feature in the SQL standard. The reason you get "true" is that the
expression

> where a in ( select a from btable where c = 10) ;

is basically reducing to "a = a".

https://wiki.postgresql.org/wiki/FAQ#Why_doesn.27t_PostgreSQL_report_a_column_not_found_error_when_using_the_wrong_name_in_a_subquery.3F

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2023-01-19 22:22:15 Re: BUG #17753: pg_dump --if-exists bug
Previous Message PG Bug reporting form 2023-01-19 18:02:11 BUG #17754: Subquery IN clause returns row matches where subquery is invalid