From: | Kovacs Zoltan Sandor <tip(at)pc10(dot)radnoti-szeged(dot)sulinet(dot)hu> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org |
Subject: | bug in views/aggregates |
Date: | 2000-10-25 12:10:07 |
Message-ID: | Pine.LNX.4.05.10010251402230.30412-100000@pc10.radnoti-szeged.sulinet.hu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-hackers |
I'm not sure if this is a reported bug or not. SELECT statements with some
aggregates on certain complex views can give terrible results. An example:
CREATE TABLE master (
id int4 not null,
no int4 check (no >= 0) default 0,
primary key (id, no),
started date check ((not started is null) or (not closed)),
received date,
starter int4 not null,
description text,
closed bool default 'f',
date_of_closing timestamp,
closed_by int4);
CREATE TABLE detail (
id int4 not null,
no_ int4 not null,
primary key (id, no_, modification, archive),
ordering int4 not null,
object int4 not null,
ordered_by int4,
quantity numeric(14,4) not null,
quality int4 not null default 1,
archive bool default 'f',
starting int4,
modification int4 not null check (modification >= 0),
foreign key (id,modification) references
master(id,no));
CREATE VIEW buggy_view AS
SELECT de.id, de.no_, de.ordering, de.object,
de.ordered_by, de.quantity, de.quality, ma.no FROM
detail de, master ma WHERE
((((ma.no >= de.starting) AND (ma.no < de.modification)) AND de.archive)
OR ((ma.no >= de.modification) AND (NOT de.archive))) GROUP BY
de.id, de.no_, de.ordering, de.object,
de.ordered_by, de.quantity, de.quality, ma.no;
INSERT INTO master VALUES (1,0,now(),now(),1,'','f',now(),1);
INSERT INTO detail VALUES (1,1,1,100,1,1000,1,'f',1,0);
INSERT INTO detail VALUES (1,2,2,101,1,2000,1,'f',1,0);
SELECT count(*) FROM buggy_view; -- I can see two rows of result! :-o
I'm using PostgreSQL 7.0.2.
I am interested in workarounds as well.
TIA, Zoltan
From | Date | Subject | |
---|---|---|---|
Next Message | Sean Kelly | 2000-10-25 13:20:45 | Re: Updating multiple bool values crashes backend |
Previous Message | Thomas Lockhart | 2000-10-25 03:26:21 | Re: Updating multiple bool values crashes backend |
From | Date | Subject | |
---|---|---|---|
Next Message | Vince Vielhaber | 2000-10-25 14:06:09 | Re: Mailing list archives available? |
Previous Message | devik | 2000-10-25 12:06:12 | Re: Unneccessary cmax in heap tuple ? |