<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D'>Pierre,<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Very interesting.  Does seem to be a bug somewhere.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Seems almost like in one case the POINT(0 0) is getting a box and in other cases it's not.  Perhaps same thing is happening with POINT EMPTY.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>I know we had a bug a while back where all the points were getting cached boxes.  This might be left over from that issue when we fixed that is my only guess.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Luckily I still have a server (about to destroy) running PostGIS 1.5.5 which should pre-date this bug and gave this query a try and it gave the below output. <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>I think because there was a time way back for some reason POINT(0 0 ) was  a stand in for POINT EMPTY and ST_AsText couldn't represent POINT EMPTY so output GEOMETRYCOLLECTION EMPTY.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Thus you see 2 instances of GEOMETRY COLLECTION (one presumably aggregating the true GEOMETRYCOLLECTION EMPTY and another aggregating the POINT(0 0) with the POINT EMPTY.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Perhaps we've got bits of our translation somewhere that sort of still thinks that at whim.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT ST_AsText(geom) txt, count(*)<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>FROM (<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT 'POINT(0 1)'::geometry geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT 'LINESTRING(0 0,0 1)'::geometry geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT 'GEOMETRYCOLLECTION EMPTY'::geometry geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT 'POINT EMPTY'::geometry geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>) foo<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>GROUP BY geom;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Output: <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>           txt            | count<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>--------------------------+-------<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> GEOMETRYCOLLECTION EMPTY |     4<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> LINESTRING(0 0,0 1)      |     1<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> GEOMETRYCOLLECTION EMPTY |     1<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> POINT(0 1)               |     1<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>(4 rows)<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Flash back to the present PostGIS 2.3/PostGIS 2.4 which is what you are seeing.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Right now EMPTY's should have null boxes and POINTS and 2 point lines should have no boxes, so they are aggregated the same.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Thus the answer should be along lines of below query.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>----<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>I would have expected the result to be something along the lines of:<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT ST_AsText(geom) txt, count(*)<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>FROM (<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT Box2D('POINT(0 0)'::geometry)::geometry AS geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT Box2D('POINT(0 0)'::geometry)::geometry  AS  geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT Box2D('POINT(0 0)'::geometry)::geometry  AS  geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT Box2D('POINT(0 1)'::geometry)::geometry  AS  geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT Box2D('LINESTRING(0 0,0 1)'::geometry)::geometry  AS geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT Box2D('GEOMETRYCOLLECTION EMPTY'::geometry)  AS geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>UNION ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>SELECT Box2D('POINT EMPTY'::geometry)  AS geom<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>) foo<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>GROUP BY geom;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>And as you pointed out, it is not.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>         txt         | count<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>---------------------+-------<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> POINT(0 0)          |     3<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> LINESTRING(0 0,0 1) |     1<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> POINT(0 1)          |     1<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> NULL                |     2<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>(4 rows)<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Don't know what to say Pierre.  You've found a gremlin lurking in the woods.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Regina<o:p></o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='margin-left:.5in'><b>From:</b> postgis-users [mailto:postgis-users-bounces@lists.osgeo.org] <b>On Behalf Of </b>Pierre Racine<br><b>Sent:</b> Tuesday, June 20, 2017 5:42 PM<br><b>To:</b> 'PostGIS Users Discussion' <postgis-users@lists.osgeo.org><br><b>Subject:</b> [postgis-users] Strange behavior with empty geometries GROUP BY<o:p></o:p></p></div></div><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>Hi,<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>When I try to count the occurrence of a number of empty geometries like this:<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT ST_AsText(geom) txt, count(*)<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>FROM (<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT(0 1)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'LINESTRING(0 0,0 1)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'GEOMETRYCOLLECTION EMPTY'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT EMPTY'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>) foo<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>GROUP BY geom;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>The 'GEOMETRYCOLLECTION EMPTY' and the 'POINT EMPTY' do not aggregate and I get:<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>txt                                                                         count<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>POINT(0 0)                                                         2<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>POINT EMPTY                                                   1<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>POINT(0 0)                                                         1<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>LINESTRING(0 0,0 1)                                      1<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>GEOMETRYCOLLECTION EMPTY                1<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>POINT(0 1)                                                         1<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>If I remove any geometry other than the two EMPTY ones like this (I removed the first one 'POINT(0 0)'), the two EMPTY geometries DO aggregate:<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT ST_AsText(geom) txt, count(*)<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>FROM (<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT(0 0)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT(0 1)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'LINESTRING(0 0,0 1)'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'GEOMETRYCOLLECTION EMPTY'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>UNION ALL<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>SELECT 'POINT EMPTY'::geometry geom<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>) foo<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>GROUP BY geom;<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>Result:<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>txt                                          count<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>POINT(0 0)                          2<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>LINESTRING(0 0,0 1)       1<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>POINT EMPTY                    2<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'>POINT(0 1)                          1<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>Any idea why empty geometries aggregation seem so dependent on what others geoms are in the table?<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>Sorry I could not build a more simple example.<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>Thanks,<o:p></o:p></p><p class=MsoNormal style='margin-left:.5in'><o:p> </o:p></p><p class=MsoNormal style='margin-left:.5in'>Pierre<o:p></o:p></p></div></body></html>