Re: Strange behavior - Mailing list pgsql-general

From Francisco Olarte
Subject Re: Strange behavior
Date
Msg-id CA+bJJbyANDsdKiMNV_yiQ=1=K6OaUzHhH1puHGgv65Gkoyvz6A@mail.gmail.com
Whole thread Raw
In response to Strange behavior  (Olivier Leprêtre <o.lepretre@gmail.com>)
List pgsql-general
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.



pgsql-general by date:

Previous
From: Olivier Leprêtre
Date:
Subject: Strange behavior
Next
From: "David G. Johnston"
Date:
Subject: Re: Strange behavior