pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
undocumented feature or bug in subquery : psql (PostgreSQL) 9.4.6 on SLES12 SP1
2+ messages / 2 participants
[nested] [flat]

* undocumented feature or bug in subquery : psql (PostgreSQL) 9.4.6 on SLES12 SP1
@ 2016-08-25 16:29  otter117@yahoo.de
  0 siblings, 1 reply; 2+ messages in thread

From: otter117@yahoo.de @ 2016-08-25 16:29 UTC (permalink / raw)
  To: pgsql-docs

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/9.4/static/functions-subquery.html
Description:

psql (PostgreSQL) 9.4.6 on SLES12 SP1
2 tables a and b
               Table "public.a"
     Column      |           Type           |   Modifiers
-----------------+--------------------------+---------------
 foo             | integer                  | not null
 bar             | integer                  | not null

               Table "public.b"
     Column      |           Type           |   Modifiers
-----------------+--------------------------+---------------
 bar             | integer                  | not null

No error when executing this statement even though table b does not contain
column foo
SELECT foo,bar FROM a WHERE foo=1 AND bar NOT IN (SELECT bar FROM b WHERE
bar > 2 AND foo=2)

Get an error on this one ERROR:  column b.foo does not exist
SELECT foo,bar FROM a WHERE foo=1 AND bar NOT IN (SELECT bar FROM b WHERE
b.bar > 2 AND b.foo=2)

It works if I remove foo from the subquery.
SELECT foo,bar FROM a WHERE foo=1 AND bar NOT IN (SELECT bar FROM b WHERE
b.bar > 2)

Do I need to qualify all columns in the subquery or is this a bug is psql
9.4.6?


-- 
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: undocumented feature or bug in subquery : psql (PostgreSQL) 9.4.6 on SLES12 SP1
@ 2016-08-26 13:07  Tom Lane <tgl@sss.pgh.pa.us>
  parent: otter117@yahoo.de
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2016-08-26 13:07 UTC (permalink / raw)
  To: otter117@yahoo.de; +Cc: pgsql-docs

otter117@yahoo.de writes:
> 2 tables a and b
>                Table &quot;public.a&quot;
>      Column      |           Type           |   Modifiers
> -----------------+--------------------------+---------------
>  foo             | integer                  | not null
>  bar             | integer                  | not null

>                Table &quot;public.b&quot;
>      Column      |           Type           |   Modifiers
> -----------------+--------------------------+---------------
>  bar             | integer                  | not null

> No error when executing this statement even though table b does not contain
> column foo
> SELECT foo,bar FROM a WHERE foo=1 AND bar NOT IN (SELECT bar FROM b WHERE
> bar > 2 AND foo=2)

No, but table a does, and that's a legal outer reference per the SQL
standard.  This is neither a bug nor undocumented.

> Do I need to qualify all columns in the subquery or is this a bug is psql
> 9.4.6?

It's often wise to qualify column references in multi-table queries
(subqueries or not) to ensure they are referencing what you think
they're referencing.

			regards, tom lane


-- 
Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-08-26 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-08-25 16:29 undocumented feature or bug in subquery : psql (PostgreSQL) 9.4.6 on SLES12 SP1 otter117@yahoo.de
2016-08-26 13:07 ` Tom Lane <tgl@sss.pgh.pa.us>

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