Re: Query will execute when inner query have issue - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Query will execute when inner query have issue
Date
Msg-id 5259.1579790613@sss.pgh.pa.us
Whole thread Raw
In response to Query will execute when inner query have issue  (selva kumar <selva.logic@hotmail.com>)
Responses RE: Query will execute when inner query have issue
List pgsql-bugs
selva kumar <selva.logic@hotmail.com> writes:
> We tried query in a following manner.
> SELECT * FROM A where A.id IN (SELECT B.id from B);
> In the above query Table B does not have id. But this query return all A table records

You sure that's *actually* what you wrote?  The usual mistake is to
fail to qualify the inner query's column reference at all:

SELECT * FROM A where A.id IN (SELECT id from B);

If B has no "id" column, it's still a legal SQL query, interpreted as

SELECT * FROM A where A.id IN (SELECT A.id from B);

so as long as B has any rows, the IN-test succeeds for every non-null
value of A.id.  People get burned by that all the time, but it's
acting as required by the SQL standard.

            regards, tom lane



pgsql-bugs by date:

Previous
From: "srinivasulu"
Date:
Subject: RE: BUG #16227: Loss database tables automatically in a couple of days
Next
From: Alvaro Herrera
Date:
Subject: Re: 12.1 Partitioned Table Creation Bug