]> granicus.if.org Git - postgis/commitdiff
#3018, GROUP BY geography sometimes returns duplicate rows
authorPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 23 Apr 2015 18:20:00 +0000 (18:20 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Thu, 23 Apr 2015 18:20:00 +0000 (18:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13437 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
postgis/geography_btree.c

diff --git a/NEWS b/NEWS
index 7da25d146ed9fb92426d7c306b8f1f77fd713807..457eca20199160f99be7d4c19e1a9b1eea460fb7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -96,6 +96,7 @@ PostGIS 2.2.0
   - #3061, Allow duplicate points in JSON, GML, GML ST_GeomFrom* functions
   - #3086, ST_DumpValues() crashes backend on cleanup with invalid
            band indexes
+  - #3018, GROUP BY geography sometimes returns duplicate rows
 
  * Code refactoring *
 
index dd3da79692c6c56216ea866885d053ffcc8c2d7d..23b59e064a82919e00e7b4b164f08c9d55fe4186 100644 (file)
@@ -210,7 +210,7 @@ Datum geography_eq(PG_FUNCTION_ARGS)
 
        /* Must be able to build box for each argument (ie, not empty geometry) */
        if ( ! gserialized_datum_get_gidx_p(PG_GETARG_DATUM(0), gbox1) ||
-               ! gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), gbox2) )
+            ! gserialized_datum_get_gidx_p(PG_GETARG_DATUM(1), gbox2) )
        {
                PG_RETURN_BOOL(FALSE);
        }
@@ -249,13 +249,33 @@ Datum geography_cmp(PG_FUNCTION_ARGS)
        geography_gidx_center(gbox1, &p1);
        geography_gidx_center(gbox2, &p2);
 
-       if ( p1.x > p2.x && p1.y > p2.y && p1.z > p2.z )
+       if  ( ! FP_EQUALS(p1.x, p2.x) )
+       {
+               if  (p1.x < p2.x)
+               {
+                       PG_RETURN_INT32(-1);
+               }
                PG_RETURN_INT32(1);
+       }
 
-       if ( FP_EQUALS(p1.x, p2.x) && FP_EQUALS(p1.y, p2.y) && FP_EQUALS(p1.z, p2.z) )
-               PG_RETURN_INT32(0);
+       if  ( ! FP_EQUALS(p1.y, p2.y) )
+       {
+               if  (p1.y < p2.y)
+               {
+                       PG_RETURN_INT32(-1);
+               }
+               PG_RETURN_INT32(1);
+       }
 
-       PG_RETURN_INT32(-1);
+       if  ( ! FP_EQUALS(p1.z, p2.z) )
+       {
+               if  (p1.z < p2.z)
+               {
+                       PG_RETURN_INT32(-1);
+               }
+               PG_RETURN_INT32(1);
+       }
 
+       PG_RETURN_INT32(0);
 }