BUG #4290: wrong double subselect with aggregate function - Mailing list pgsql-bugs

From Andreas
Subject BUG #4290: wrong double subselect with aggregate function
Date
Msg-id 200807091542.m69FgOeC088180@wwwmaster.postgresql.org
Whole thread Raw
Responses Re: BUG #4290: wrong double subselect with aggregate function
List pgsql-bugs
The following bug has been logged online:

Bug reference:      4290
Logged by:          Andreas
Email address:      postgresql@elbrief.de
PostgreSQL version: 8.3.3
Operating system:   Linux
Description:        wrong double subselect with aggregate function
Details:

select version() ;
                                     version
----------------------------------------------------------------------------
------
 PostgreSQL 8.3.3 on i486-pc-linux-gnu, compiled by GCC cc (Debian 4.3.1-1)
4.3.1

create table a (
  id serial primary key
) ;

create table b (
  id serial primary key
  , aid int not null references a
) ;

create table c (
  id serial primary key
  , aid int not null references a
) ;

create table d (
  id serial primary key
  , bid int not null references b
  , cid int references b
) ;

insert into a ( id ) values ( default ) , ( default ) ;
insert into b ( aid ) values ( 1 ) , ( 2 ) ;
insert into c ( aid ) values ( 1 ) , ( 1 ) , ( 2 ) , ( 2 ) ;
insert into d ( bid ) values ( 1 ) , ( 2 ) ;
select
 ( select min( c.id ) from c where c.aid = ( select b.aid from b where b.id
= d.bid ) ) as min_c_id
  , ( select b.aid from b where b.id = d.bid ) as b_aid
  , ( select min( c.id ) from c where c.aid = 1 ) as min_c_id_1
  , ( select min( c.id ) from c where c.aid = 2 ) as min_c_id_2
from d ;

 min_c_id | b_aid | min_c_id_1 | min_c_id_2
----------+-------+------------+------------
        1 |     1 |          1 |          3
        1 |     2 |          1 |          3

I expected for min_c_id in the second row 3.

Best Regards
Andreas

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #4289: drop owned by report ERROR: cache lookup failed for relation 16390
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #4290: wrong double subselect with aggregate function