Opened 13 years ago

Closed 13 years ago

#1078 closed defect (invalid)

ST_Difference with NULL as second argument

Reported by: nicklas Owned by: nicklas
Priority: medium Milestone: PostGIS 2.0.0
Component: postgis Version: master
Keywords: Cc:

Description

I think that ST_Difference should return the first argument if the second argument is NULL. Now it returns NULL or nothing.

This is specially interesting in situation like the one described here, with a left or right join to catch the none intersecting ones:

http://gis.stackexchange.com/questions/11592/difference-between-two-layers-in-postgis

So I would like to commit this:

Index: postgis.sql.in.c
===================================================================
--- postgis.sql.in.c	(revision 7521)
+++ postgis.sql.in.c	(working copy)
@@ -3199,7 +3199,7 @@
 CREATE OR REPLACE FUNCTION ST_Difference(geometry,geometry)
 	RETURNS geometry
 	AS 'MODULE_PATHNAME','difference'
-	LANGUAGE 'C' IMMUTABLE STRICT;
+	LANGUAGE 'C' IMMUTABLE;
 
 -- PostGIS equivalent function: boundary(geometry)
 CREATE OR REPLACE FUNCTION ST_Boundary(geometry)
Index: lwgeom_geos.c
===================================================================
--- lwgeom_geos.c	(revision 7521)
+++ lwgeom_geos.c	(working copy)
@@ -1493,8 +1493,12 @@
 	int is3d;
 	int srid;
 
-	PROFSTART(PROF_QRUN);
-
+         /* Return the first geom if the second geom is null */
+         if (PG_ARGISNULL(1))
+                 PG_RETURN_DATUM(PG_GETARG_DATUM(0));	
+	 
+	 PROFSTART(PROF_QRUN);
+		 
 	geom1 = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 	geom2 = (PG_LWGEOM *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
 

Any objections?

/Nicklas

Change History (3)

comment:1 by pramsey, 13 years ago

Take this to the devel list. It's ok for st_difference(geometry, empty). But NULL has special expectations in a database. See the difference between

select btrim('this', 't');
select btrim('this', NULL);

for an analogue to your case.

comment:2 by robe, 13 years ago

I'm against this. See my note to the guy on forum.

comment:3 by nicklas, 13 years ago

Resolution: invalid
Status: newclosed

Ok, I see the logic.

I haven't thought that much about the null-usage before.

Thanks and sorry for the noise

Note: See TracTickets for help on using tickets.