Re: BUG #14919: Invalid column in sub select is still a valid select

From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Tanes Sriviroolchai <tanes(at)siamscan(dot)net>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14919: Invalid column in sub select is still a valid select
Date: 2017-11-20 14:16:20
Message-ID: CAL9smLCcQZo8pZcF0XNxkus3Y_3zprdXJXNMi7hx7XLS3EOCYw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Nov 20, 2017 at 3:49 PM, Tanes Sriviroolchai <tanes(at)siamscan(dot)net>
wrote:

> Really? The fact that 1st statement doen't end in exception throwing is
> ok? (While the same sub select executes with exception throwing.)
>
> select * from a where id=(select id from b where descr='A');
>

Because "b" doesn't have a column called "id", this is the same as:

select * from a where id=(select a.id from b where descr='A');

and that's a valid, though slightly silly, query. In other words, you
accidentally wrote a correlated subquery. Some people consider it good
practice to qualify column references with the name of the table when
there's more than one column in scope. If you had written:

select * from a where id=(select b.id from b where b.descr='A');

you would have noticed that you made a mistake, due to the exception this
query raises.

.m

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-11-20 17:55:18 Re: BUG #14917: process hang on create index
Previous Message Tanes Sriviroolchai 2017-11-20 13:49:17 Re: BUG #14919: Invalid column in sub select is still a valid select