dbTalk Databases Forums  

[BUGS] BUG #1682: subselect generates multiple rows

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1682: subselect generates multiple rows in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
D.J. Kniep
 
Posts: n/a

Default [BUGS] BUG #1682: subselect generates multiple rows - 05-27-2005 , 08:24 AM







The following bug has been logged online:

Bug reference: 1682
Logged by: D.J. Kniep
Email address: dick (AT) kniep (DOT) nl
PostgreSQL version: 8.0.3
Operating system: Linux
Description: subselect generates multiple rows
Details:

table1:
id content
1 John Doe
2 Peter Gabriel

view2
id extra1 extra2
1 a1 b1
1 a1 b1
2 a1 b3
3 a1 b5

query:
select * from table1 t1 where t1.id in (select t2.id from view2 t2 where
extra1 = 'a1')

produces:

id content
1 John Doe
1 John Doe
2 Peter Gabriel

which obviously should be:

id content
1 John Doe
2 Peter Gabriel

I might not be reachable on my mailaddress because of US imposed
restrictions. A big range of the IP addresses of the provider I am using are
marked as spam generating (which in fact is NOT true at least not for my IP
address), and blacklisted and this makes it effectively impossible for me to
use the mailinglist.

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #1682: subselect generates multiple rows - 05-27-2005 , 09:38 AM






"D.J. Kniep" <dick (AT) kniep (DOT) nl> writes:
Quote:
query:
select * from table1 t1 where t1.id in (select t2.id from view2 t2 where
extra1 = 'a1')

produces:

id content
1 John Doe
1 John Doe
2 Peter Gabriel
Not for me ---

regression=# create table table1(id int, context text);
CREATE TABLE
regression=# create table view2(id int, extra1 text, extra2 text);
CREATE TABLE
regression=# insert into table1 values(1,'John Doe');
INSERT 156512 1
regression=# insert into table1 values(2,'Peter Gabriel');
INSERT 156513 1
regression=# insert into view2 values(1,'a1','b1');
INSERT 156514 1
regression=# insert into view2 values(1,'a1','b1');
INSERT 156515 1
regression=# insert into view2 values(2,'a1','b3');
INSERT 156516 1
regression=# insert into view2 values(3,'a1','b5');
INSERT 156517 1
regression=# select * from table1 t1 where t1.id in (select t2.id from view2 t2
where extra1 = 'a1');
id | context
----+---------------
1 | John Doe
2 | Peter Gabriel
(2 rows)

We'll need a more reproducible test case.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #3  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] BUG #1682: subselect generates multiple rows - 05-27-2005 , 09:49 AM



On Fri, May 27, 2005 at 08:55:50AM +0100, D.J. Kniep wrote:
Quote:
id content
1 John Doe
1 John Doe
2 Peter Gabriel
I couldn't reproduce these results with the test data and query you
provided, but my table and view definitions probably differed from
yours. Could you post a complete example? That is, all CREATE,
INSERT, and SELECT statements that somebody could execute in an
empty database to reproduce the results you get.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.