[postgis-devel] ST_MakePolygon returns null geometry when passedNULL or empty array

Kevin Neufeld kneufeld at refractions.net
Tue Jul 8 10:53:44 PDT 2008


Hi Regina,

I get the same as you. It looks like quirkiness of postgres if you ask me.

As a second parameter to ST_MakePolygon, I agree these all produce 
different results:

ARRAY(SELECT 'LINESTRING EMPTY'::geometry WHERE false)
-> produces a valid polygon with no holes
ARRAY[NULL]
-> errors on "hole 0 is not a line"
NULL
-> produces no polygon, just null

I think the best course is to be clear in the docs that the second 
parameter must not be null and must be a valid set of LINESTRINGs, 
passing ST_IsValid.

Cheers,
-- Kevin

Obe, Regina wrote:
> Okay this is puzzling me.  I wasn't getting errors, just getting NULL back.
>  
> What do you get if you run this
>  
> SELECT ST_IsValid(the_geom), ST_AsText(the_geom)
> FROM (
>    SELECT ST_MakePolygon(
>      'LINESTRING(0 0, 0 8, 8 8, 8 0, 0 0)'::geometry,
>      ARRAY(SELECT 'LINESTRING(1 1, 0 8, 8 8, 8 0, 1 1)'::geometry WHERE 
> false)) AS the_geom
>    ) AS foo;
>  
> The test I ran should have been the same as this, but this actually 
> works the way I would expect it to returning a geometry when given an 
> empty geometry array.  Although I just ran on 1.3.2  and I think earlier 
> I was testing on 1.3.3 and it was slightly more complicated than the 
> above so I'll need to retry my example to make sure I was mistaken and 
> its not just a version difference.
>  
> Just plain null - doesn't give me an error as an ARRAY[NULL] but returns 
> NULL
>  
> SELECT ST_IsValid(the_geom), ST_AsText(the_geom)
> FROM (
>    SELECT ST_MakePolygon(
>      'LINESTRING(0 0, 0 8, 8 8, 8 0, 0 0)'::geometry,
>      NULL) AS the_geom
>    ) AS foo;
> Thanks,
> Regina
>  
> 



More information about the postgis-devel mailing list