Re: [GENERAL] why isn't this subquery wrong?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: [GENERAL] why isn't this subquery wrong?
Дата
Msg-id CAKFQuwYhLMSzcJtHx=5vV5uqUwdc2nan_A_nKkBZRMdtFe4khw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [GENERAL] why isn't this subquery wrong?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Thu, Apr 20, 2017 at 3:43 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
jonathan vanasco <postgres@2xlp.com> 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.

​I added an FAQ entry to the wiki​ for this question:


David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: [GENERAL] why isn't this subquery wrong?
Следующее
От: Akshay Joshi
Дата:
Сообщение: [GENERAL] pgAdmin4 needs information of v10 SCRAM authentication