pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shoaib Mir <shoaibmir@gmail.com>
To: Michael Glaesemann <grzm@seespotcode.net>
Cc: Postgres SQL language list <pgsql-sql@postgresql.org>
Subject: Re: subquery abnormal behavior
Date: Mon, 11 Dec 2006 12:24:29 +0500
Message-ID: <bf54be870612102324i50635183s8dab2f3af55f5cfc@mail.gmail.com> (raw)
In-Reply-To: <EE83C543-2CCD-41CD-8AEA-BD337673FF7B@seespotcode.net>
References: <bf54be870612102248j33f63ca1gd89e76d536a0262c@mail.gmail.com>
	<EE83C543-2CCD-41CD-8AEA-BD337673FF7B@seespotcode.net>

Oh that explains a lot...

Thank you,
-------------
Shoaib Mir
EnterpriseDB (www.enterprisedb.com)


On 12/11/06, Michael Glaesemann <grzm@seespotcode.net> wrote:
>
>
> On Dec 11, 2006, at 15:48 , Shoaib Mir wrote:
>
> > create table myt1 (a numeric);
> > create table myt2 (b numeric);
> >
> > select a from myt1 where a in (select a from myt2);
> >
> > This should be giving an error that column 'a' does not exist in
> > myt2 but it runs with any error...
>
> The a in the IN clause is the same a in outer expression. This is in
> effect:
>
> select a from myt1 where a = a;
>
> Now, if you were to say
>
> select a from myt1 where a in (select myt2.a from myt2);
> ERROR:  column myt2.a does not exist
> LINE 1: select a from myt1 where a in (select myt2.a from myt2);
>
> And if you were to instead have
> create table myt1 (a numeric);
> CREATE TABLE
> create table myt2 (b numeric);
> CREATE TABLE
> insert into myt1(a) values (1), (2);
> INSERT 0 2
> insert into myt2 (b) values (3), (4), (2);
> INSERT 0 3
> create table myt3 (a numeric);
> CREATE TABLE
> insert into myt3 (a) values (2), (3),(4);
> INSERT 0 3
> test=# select a from myt1 where a in (select a from myt3);
> a
> ---
> 2
> (1 row)
>
> It looks like PostgreSQL treats it as a natural join like
>
> select a from myt1 natural join myt3;
>
> Hope this helps.
>
> Michael Glaesemann
> grzm seespotcode net
>
>
>

view thread (6+ messages)  latest in thread

Message-ID: <bf54be870612102324i50635183s8dab2f3af55f5cfc@mail.gmail.com>
Permalink:  ../bf54be870612102324i50635183s8dab2f3af55f5cfc@mail.gmail.com/
Also on:    postgresql.org/message-id/bf54be870612102324i50635183s8dab2f3af55f5cfc@mail.gmail.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: shoaibmir@gmail.com, grzm@seespotcode.net
  Subject: Re: subquery abnormal behavior
  In-Reply-To: <bf54be870612102324i50635183s8dab2f3af55f5cfc@mail.gmail.com>

* 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