Re: Re: Does PostgreSQL support EXISTS?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Nils Zonneveld <nils(at)mbit(dot)nl>, pgsql-general(at)postgresql(dot)org
Subject: Re: Re: Does PostgreSQL support EXISTS?
Date: 2001-06-13 13:51:46
Message-ID: 26043.992440306@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> On postgres at least, exists is faster than in.
> They are equivalent though.

Not really.

For one thing, IN can return a NULL (don't know) result; EXISTS cannot.

regression=# select * from foo;
f1
----
1

(2 rows)

regression=# select 2 in (select f1 from foo);
?column?
----------

(1 row)

regression=# select exists (select 1 from foo where f1 = 2);
?column?
----------
f
(1 row)

Yes, this behavior is spec-compliant. Think: we don't know what the NULL
represents, therefore we don't know whether 2 is in the column or not,
therefore IN should return NULL.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-06-13 14:02:05 Re: [Help] AGGREGATE problem w/v7.0
Previous Message Gregory Wood 2001-06-13 13:47:09 Re: PLPGSQL: Using Transactions and locks