BUG #1629: subquery IN returns incorrect results - Mailing list pgsql-bugs
From | mike g |
---|---|
Subject | BUG #1629: subquery IN returns incorrect results |
Date | |
Msg-id | 20050426202350.3CF6BF0DE0@svr2.postgresql.org Whole thread Raw |
Responses |
Re: BUG #1629: subquery IN returns incorrect results
Re: BUG #1629: subquery IN returns incorrect results |
List | pgsql-bugs |
The following bug has been logged online: Bug reference: 1629 Logged by: mike g Email address: mike@thegodshalls.com PostgreSQL version: 8.0 Operating system: Windows 2000 Description: subquery IN returns incorrect results Details: If I run this query: SELECT distinct CAST(newprogram as varchar(60)) FROM (SELECT t.propnbr, CASE WHEN t.propname = 'A' THEN 'Am' WHEN t.propname = 'B' THEN 'AMm' WHEN t.propname = 'C' THEN 'I might vanish' WHEN t.propname = 'D' THEN 'Bem' WHEN t.propname = 'E' THEN 'Cm' WHEN t.propname = 'F' THEN 'Clm' WHEN t.propname = 'G' THEN 'Com' WHEN t.propname = 'H' THEN 'Dm' WHEN t.propname = 'I' THEN 'Er' WHEN t.propname = 'J' THEN 'Err' WHEN t.propname = 'K' THEN 'Em' WHEN t.propname = 'L' THEN 'Fm' WHEN t.propname = 'M' THEN 'Fm' WHEN t.propname = 'N' THEN 'Gm' WHEN t.propname = 'O' THEN 'Hm' WHEN t.propname = 'P' THEN 'Dm' WHEN t.propname = 'Q' THEN 'Lm' WHEN t.propname = 'R' THEN 'Nm' WHEN t.propname = 'S' THEN 'Om' WHEN t.propname = 'T' THEN 'Err' WHEN t.propname = 'U' THEN 'Rm' WHEN t.propname = 'V' THEN 'Tm' WHEN t.propname = 'W' THEN 'Tm' ELSE t.propname END as newprogram FROM example_data t INNER JOIN example_data2 b ON t.propco = b.propco WHERE upper(b.serviced) = 'STATE1' and t.propname in ('A', 'B' 'C', --switch me 'D', -- and switch me 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X')) as my_data My results are: newprogram Am Bem Clm Cm Com Dm Em Er Err Fm Gm Hm Lm Nm Om Rm Tm If I just change the order of the data for the IN subquery portion SELECT distinct CAST(newprogram as varchar(60)) FROM (SELECT t.propnbr, CASE WHEN t.propname = 'A' THEN 'Am' WHEN t.propname = 'B' THEN 'AMm' WHEN t.propname = 'C' THEN 'I might vanish' WHEN t.propname = 'D' THEN 'Bem' WHEN t.propname = 'E' THEN 'Cm' WHEN t.propname = 'F' THEN 'Clm' WHEN t.propname = 'G' THEN 'Com' WHEN t.propname = 'H' THEN 'Dm' WHEN t.propname = 'I' THEN 'Er' WHEN t.propname = 'J' THEN 'Err' WHEN t.propname = 'K' THEN 'Em' WHEN t.propname = 'L' THEN 'Fm' WHEN t.propname = 'M' THEN 'Fm' WHEN t.propname = 'N' THEN 'Gm' WHEN t.propname = 'O' THEN 'Hm' WHEN t.propname = 'P' THEN 'Dm' WHEN t.propname = 'Q' THEN 'Lm' WHEN t.propname = 'R' THEN 'Nm' WHEN t.propname = 'S' THEN 'Om' WHEN t.propname = 'T' THEN 'Err' WHEN t.propname = 'U' THEN 'Rm' WHEN t.propname = 'V' THEN 'Tm' WHEN t.propname = 'W' THEN 'Tm' ELSE t.propname END as newprogram FROM example_data t INNER JOIN example_data2 b ON t.propco = b.propco WHERE upper(b.serviced) = 'STATE1' and t.propname in ('A', 'B' 'D', -- and switch me 'C', --switch me 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X')) as my_data Gives this for a result Am Clm Cm Com Dm Em Er Err Fm Gm Hm I might vanish Lm Nm Om Rm Tm I will email a pg_dump of the two tables on request. The results of either version are incorrect. If you remove the IN subquery and replace each case with t.propname = 'A' or... then correct results returned: AMm Am Bem Clm Cm Com Dm Em Er Err Fm Gm Hm I might vanish Lm Nm Om Rm Tm
pgsql-bugs by date: