From: | Pantelis Theodosiou <ypercube(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | reva(dot)d91(at)gmail(dot)com, pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #14514: Bug in Subquery |
Date: | 2017-01-25 16:05:00 |
Message-ID: | CAE3TBxyr-TZXGKUL1aBHbcKszA=-iaGe64NT2QCXWwR-mR+rPg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Wed, Jan 25, 2017 at 3:29 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> reva(dot)d91(at)gmail(dot)com writes:
> > It is ignoring the invalid columns in subquery,Instead of throwing the
> error
> > 'Column does not exist'.
>
> > (eg):
> > select * from emp where (empname,empid,empno) in(selec emname,emid,emno
> from
> > em_details)
>
> > Note:There is no emno in em_details table.
>
> Maybe not, but if there is one in emp, then this query is legal per
> SQL spec --- emno is an outer reference.
>
> regards, tom lane
>
What Tom says above, the query is legal SQL if the column exists in either
table.
You should use aliases (or just prefix the columns with their table name
and dot):
select e.* from emp as e
where (e.empname, e.empid, e.empno) in
(select ed.emname, ed.emid, ed.emno
from em_details as ed)
This way the query will work as you expected, either give a result (if the
3 columns exist in em_details) or give you an error if not.
From | Date | Subject | |
---|---|---|---|
Next Message | Tomasz Szypowski | 2017-01-25 16:16:52 | Re: could not fork autovacuum worker process: No error |
Previous Message | Tom Lane | 2017-01-25 16:04:56 | Re: could not fork autovacuum worker process: No error |