Re: BUG #4936: Bad result for SQL query

Lists: pgsql-bugs
From: "Mathieu Dupuis" <mdupuis(at)premieresloges(dot)ca>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #4936: Bad result for SQL query
Date: 2009-07-23 15:45:01
Message-ID: 200907231545.n6NFj1cs051379@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 4936
Logged by: Mathieu Dupuis
Email address: mdupuis(at)premieresloges(dot)ca
PostgreSQL version: 8.4.0
Operating system: Ubuntu
Description: Bad result for SQL query
Details:

I have found a probleme with a sql query that I run in one of my program.

I have simplified the query as much as I can to figure out what the problem
is. Have have also compere the result with the same data between postgresql
8.4 and postgresql 8.3 and the resultset is different.

Here are the result of the simplest query that recreate the problem, as you
can see the p.id and sod.performance_id are the same because I join on those
fields but if I compare with one, I have a different result that if I
compare the other.

-- 1) Return 1 rows (bad)
select p.performance_datetime, sod.id
from saleorder_details sod, performance p, sale
where p.id in (select 21030434)
and p.id = sod.performance_id
and sale.id = sod.sale_id;

-- 2) Return many rows (good)
select p.performance_datetime, sod.id
from saleorder_details sod, performance p, sale
where p.id in (21030434)
and p.id = sod.performance_id
and sale.id = sod.sale_id;

-- 3) Return many rows (good)
select p.performance_datetime, sod.id
from saleorder_details sod, performance p, sale
where sod.performance_id in (select 21030434)
and p.id = sod.performance_id
and sale.id = sod.sale_id;


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Mathieu Dupuis" <mdupuis(at)premieresloges(dot)ca>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4936: Bad result for SQL query
Date: 2009-07-23 16:22:22
Message-ID: 18160.1248366142@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Mathieu Dupuis" <mdupuis(at)premieresloges(dot)ca> writes:
> Here are the result of the simplest query that recreate the problem, as you
> can see the p.id and sod.performance_id are the same because I join on those
> fields but if I compare with one, I have a different result that if I
> compare the other.

These queries are pretty much entirely useless without the table
definitions and sample data.

regards, tom lane