pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14919: Invalid column in sub select is still a valid select
5+ messages / 4 participants
[nested] [flat]
* BUG #14919: Invalid column in sub select is still a valid select
@ 2017-11-20 07:26 tanes@siamscan.net
2017-11-20 13:09 ` Re: BUG #14919: Invalid column in sub select is still a valid select Michael Paquier <michael.paquier@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: tanes@siamscan.net @ 2017-11-20 07:26 UTC (permalink / raw)
To: pgsql-bugs; +Cc: tanes@siamscan.net
The following bug has been logged on the website:
Bug reference: 14919
Logged by: Tanes Sriviroolchai
Email address: tanes@siamscan.net
PostgreSQL version: 9.3.18
Operating system: Ubuntu 14.04
Description:
Not sure if this is a bug or feature but when I query with sub select while
sub select has invalid column the query is still valid and running. For
example:
create temp table a ( id integer, descr text);
create temp table b ( b_id integer, descr text);
# select * from a where id=(select id from b where descr='A');
id | descr
----+-------
(0 rows)
# select id from b where descr='A';
ERROR: column "id" does not exist
LINE 1: select id from b where descr='A';
^
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14919: Invalid column in sub select is still a valid select
2017-11-20 07:26 BUG #14919: Invalid column in sub select is still a valid select tanes@siamscan.net
@ 2017-11-20 13:09 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-20 13:49 ` Re: BUG #14919: Invalid column in sub select is still a valid select Tanes Sriviroolchai <tanes@siamscan.net>
0 siblings, 1 reply; 5+ messages in thread
From: Michael Paquier @ 2017-11-20 13:09 UTC (permalink / raw)
To: tanes@siamscan.net; +Cc: pgsql-bugs
On Mon, Nov 20, 2017 at 4:26 PM, <tanes@siamscan.net> wrote:
> Not sure if this is a bug or feature but when I query with sub select while
> sub select has invalid column the query is still valid and running. For
> example:
>
> create temp table a ( id integer, descr text);
> create temp table b ( b_id integer, descr text);
>
> # select * from a where id=(select id from b where descr='A');
>
> id | descr
> ----+-------
> (0 rows)
>
> # select id from b where descr='A';
>
> ERROR: column "id" does not exist
> LINE 1: select id from b where descr='A';
> ^
There is no bug here. The subquery should look at the column b_id
which is defined for relation b, so the error is normal.
--
Michael
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14919: Invalid column in sub select is still a valid select
2017-11-20 07:26 BUG #14919: Invalid column in sub select is still a valid select tanes@siamscan.net
2017-11-20 13:09 ` Re: BUG #14919: Invalid column in sub select is still a valid select Michael Paquier <michael.paquier@gmail.com>
@ 2017-11-20 13:49 ` Tanes Sriviroolchai <tanes@siamscan.net>
2017-11-20 14:16 ` Re: BUG #14919: Invalid column in sub select is still a valid select Marko Tiikkaja <marko@joh.to>
0 siblings, 1 reply; 5+ messages in thread
From: Tanes Sriviroolchai @ 2017-11-20 13:49 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: pgsql-bugs
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');
On Nov 20, 2017 20:09, "Michael Paquier" <michael.paquier@gmail.com> wrote:
On Mon, Nov 20, 2017 at 4:26 PM, <tanes@siamscan.net> wrote:
> Not sure if this is a bug or feature but when I query with sub select
while
> sub select has invalid column the query is still valid and running. For
> example:
>
> create temp table a ( id integer, descr text);
> create temp table b ( b_id integer, descr text);
>
> # select * from a where id=(select id from b where descr='A');
>
> id | descr
> ----+-------
> (0 rows)
>
> # select id from b where descr='A';
>
> ERROR: column "id" does not exist
> LINE 1: select id from b where descr='A';
> ^
There is no bug here. The subquery should look at the column b_id
which is defined for relation b, so the error is normal.
--
Michael
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14919: Invalid column in sub select is still a valid select
2017-11-20 07:26 BUG #14919: Invalid column in sub select is still a valid select tanes@siamscan.net
2017-11-20 13:09 ` Re: BUG #14919: Invalid column in sub select is still a valid select Michael Paquier <michael.paquier@gmail.com>
2017-11-20 13:49 ` Re: BUG #14919: Invalid column in sub select is still a valid select Tanes Sriviroolchai <tanes@siamscan.net>
@ 2017-11-20 14:16 ` Marko Tiikkaja <marko@joh.to>
2017-11-21 00:46 ` Re: BUG #14919: Invalid column in sub select is still a valid select Tanes Sriviroolchai <tanes@siamscan.net>
0 siblings, 1 reply; 5+ messages in thread
From: Marko Tiikkaja @ 2017-11-20 14:16 UTC (permalink / raw)
To: Tanes Sriviroolchai <tanes@siamscan.net>; +Cc: Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs
On Mon, Nov 20, 2017 at 3:49 PM, Tanes Sriviroolchai <tanes@siamscan.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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #14919: Invalid column in sub select is still a valid select
2017-11-20 07:26 BUG #14919: Invalid column in sub select is still a valid select tanes@siamscan.net
2017-11-20 13:09 ` Re: BUG #14919: Invalid column in sub select is still a valid select Michael Paquier <michael.paquier@gmail.com>
2017-11-20 13:49 ` Re: BUG #14919: Invalid column in sub select is still a valid select Tanes Sriviroolchai <tanes@siamscan.net>
2017-11-20 14:16 ` Re: BUG #14919: Invalid column in sub select is still a valid select Marko Tiikkaja <marko@joh.to>
@ 2017-11-21 00:46 ` Tanes Sriviroolchai <tanes@siamscan.net>
0 siblings, 0 replies; 5+ messages in thread
From: Tanes Sriviroolchai @ 2017-11-21 00:46 UTC (permalink / raw)
To: Marko Tiikkaja <marko@joh.to>; +Cc: Michael Paquier <michael.paquier@gmail.com>; pgsql-bugs
Ok. Got it.
On Nov 20, 2017 21:16, "Marko Tiikkaja" <marko@joh.to> wrote:
> On Mon, Nov 20, 2017 at 3:49 PM, Tanes Sriviroolchai <tanes@siamscan.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
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2017-11-21 00:46 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-20 07:26 BUG #14919: Invalid column in sub select is still a valid select tanes@siamscan.net
2017-11-20 13:09 ` Michael Paquier <michael.paquier@gmail.com>
2017-11-20 13:49 ` Tanes Sriviroolchai <tanes@siamscan.net>
2017-11-20 14:16 ` Marko Tiikkaja <marko@joh.to>
2017-11-21 00:46 ` Tanes Sriviroolchai <tanes@siamscan.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox