pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: yossi.eilaty@gong.io
Subject: BUG #15128: Erroneous inner query is executing with wrong results
Date: Thu, 22 Mar 2018 14:25:01 +0000
Message-ID: <152172870101.9509.2495966056168831824@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15128
Logged by:          Yossi Eilaty
Email address:      yossi.eilaty@gong.io
PostgreSQL version: 9.6.2
Operating system:   x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2
Description:        

Consider the following tables:
CREATE TABLE a (
  r BIGINT,
  y BIGINT
);
CREATE TABLE b (
  x BIGINT,
  y BIGINT
);

with the following data:

INSERT INTO a (r, y) VALUES (1, 1);
INSERT INTO a (r, y) VALUES (2, 2);

INSERT INTO b (x, y) VALUES (1, 1);
INSERT INTO b (x, y) VALUES (2, 2);

If I run the following query:

SELECT y
FROM b
WHERE x IN (SELECT x
            FROM (SELECT r
                  FROM a
                  WHERE y = 1) the_x);

I get, as a result, the y value of all rows of table b, which is wrong since
the inner query 

SELECT x
            FROM (SELECT r
                  FROM a
                  WHERE y = 1) the_x

is wrong and if run solely returns the error "[42703] ERROR: column "x" does
not exist", which is correct.

The same thing happens for the following query:

SELECT y
FROM b
WHERE x IN (SELECT x
            FROM (SELECT x
                  FROM a
                  WHERE y = 1) the_x);

where, again, the innermost query is wrong (there's no x in a).




view thread (2+ messages)  latest in thread

Message-ID: <152172870101.9509.2495966056168831824@wrigleys.postgresql.org>
Permalink:  ../152172870101.9509.2495966056168831824@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/152172870101.9509.2495966056168831824@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, yossi.eilaty@gong.io
  Subject: Re: BUG #15128: Erroneous inner query is executing with wrong results
  In-Reply-To: <152172870101.9509.2495966056168831824@wrigleys.postgresql.org>
  References: <152172870101.9509.2495966056168831824@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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