Olivier:
On Sat, Oct 10, 2020 at 6:13 PM Olivier Leprêtre <o.lepretre@gmail.com> wrote:
> I’m surprised by this behavior I noticed in pgadmin3 and postgresql 9.6
...
> select v1 from test1 where v1 not in (select v1 from test2)
This is called a correlated subquery ( google and search for it, it is
even in wikipedia ). It has many uses.
Basically, it refers to the v1 from the outside query.
Get in the habit of using (potentially aliased ) column names whenever
you have any moderately complex query, i.e. if the inner v1 would have
been v2 ( due to a typo ), writing your query as :
select t1.v1 from test1 as t1 wher t1.v1 not in ( select t2.v1 from
test2 as t2 )
Would have caught it.
Francisco Olarte.