dbTalk Databases Forums  

[BUGS] UNION makes strange duplicates

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


Discuss [BUGS] UNION makes strange duplicates in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tomasz Brzezina
 
Posts: n/a

Default [BUGS] UNION makes strange duplicates - 05-27-2005 , 08:24 AM






--------------
$psql -V
psql (PostgreSQL) 7.4.7
contains support for command-line editing
--------------
I have table with two _id (document_id and document_store_id). And I
have a view:

SELECT document_items.document_store_id AS document_id,
document_items.vat_type_id, vat_type_value,
sum(document_items.document_item_value) AS document_netto_value
FROM document_items
JOIN vat_type ON document_items.vat_type_id = vat_type.vat_type_id
GROUP BY document_items.document_store_id,
document_items.vat_type_id, vat_type_value
UNION
SELECT document_items.document_id, document_items.vat_type_id,
vat_type_value, sum(document_items.document_item_value) AS
document_netto_value
FROM document_items
JOIN vat_type ON document_items.vat_type_id = vat_type.vat_type_id
GROUP BY document_items.document_id, document_items.vat_type_id,
vat_type_value;

each of these two SELECTs almost always produce the same results
(because document_store_id almost always is equal to document_id , so
the result of VIEW should be exact the same as result of each SELECT.

BUT it isn't - example:
(SELECT * FROM document_values_by_vat WHERE document_id = '65615')

document_id vat_type_id vat_type_value document_netto_value
65615 1 0 0
65615 4 0.07 -12.5327
65615 5 0.22 -7.31148
65615 5 0.22 -7.31148

the expected result is:
document_id vat_type_id vat_type_value document_netto_value
65615 1 0 0
65615 4 0.07 -12.5327
65615 5 0.22 -7.31148

the result of first select is:
document_id vat_type_id vat_type_value document_netto_value
65615 1 0 0
65615 4 0.07 -12.5327
65615 5 0.22 -7.31148

the result of second select is:
document_id vat_type_id vat_type_value document_netto_value
65615 1 0 0
65615 4 0.07 -12.5327
65615 5 0.22 -7.31148

Any ideas?
--
T.

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

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

Default Re: [BUGS] UNION makes strange duplicates - 05-27-2005 , 10:04 AM






Tomasz Brzezina <biuro (AT) sam (DOT) w3.pl> writes:
Quote:
document_id vat_type_id vat_type_value document_netto_value
65615 1 0 0
65615 4 0.07 -12.5327
65615 5 0.22 -7.31148
65615 5 0.22 -7.31148
Perhaps document_item_value is float4, and there is some low-order-bit
difference in the sums?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


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.