Diferences between IN and EXISTS? - Mailing list pgsql-general

From Edson Richter
Subject Diferences between IN and EXISTS?
Date
Msg-id BLU0-SMTP2206E3D769625F245425A88CF020@phx.gbl
Whole thread Raw
Responses Re: Diferences between IN and EXISTS?  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general
Hi!

Assumptions: PostgreSQL 9.2.2, Win64, already run vacumm full freeze
analyze. No problems in the database. I know there are 1247 records to
be found.
Why does these queries return different results:


select count(*) from parcela
where id not in (select parcela_id from cadastroservicoparcela);

count
--------
0


select count(*) from parcela
where not exists (select 1 from cadastroservicoparcela where parcela_id
= parcela.id);

count
--------
1247


I can't figure out, I did expect that the first one returns exactly same
result!
Could null values in cadastroservicoparcela.parcela_id affect the first
query?


Thanks,

Edson

pgsql-general by date:

Previous
From: "Carlo Stonebanks"
Date:
Subject: Re: What language is faster, C or PL/PgSQL?
Next
From: Pavel Stehule
Date:
Subject: Re: Diferences between IN and EXISTS?