]> granicus.if.org Git - postgis/commitdiff
Handle NULL geometry values in pgsql2shp
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Jul 2019 16:32:03 +0000 (16:32 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 29 Jul 2019 16:32:03 +0000 (16:32 +0000)
References #4209

git-svn-id: http://svn.osgeo.org/postgis/trunk@17639 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
loader/pgsql2shp-core.c
postgis/postgis.sql.in

diff --git a/NEWS b/NEWS
index 557de7d265afc242afd6f5e33cff36521a867b3b..0d27cda695f4ed9396771fa0766a1e752c645e73 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ Additional features enabled if you are running Proj6+ and PostgreSQL 12
   - #4271, postgis_extensions_upgrade() also updates after pg_upgrade (Raúl Marín)
   - #4403, Support for shp2pgsql ability to reproject with copy mode (-D) (Regina Obe)
   - #4466, Fix undefined behaviour in _postgis_gserialized_stats (Raúl Marín)
+  - #4209, Handle NULL geometry values in pgsql2shp (Paul Ramsey)
 
 PostGIS 3.0.0alpha3
 2019/07/01
index aa9c26b5e07abf15761adda1f972a1218073ee8b..1b0a650c1e679ac4078856ee207b81780137859e 100644 (file)
@@ -887,15 +887,15 @@ getTableInfo(SHPDUMPERSTATE *state)
                {
                        query = malloc(150 + 4 * strlen(state->geo_col_name) + strlen(state->schema) + strlen(state->table));
 
-                       sprintf(query, "SELECT count(\"%s\"), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\".\"%s\" GROUP BY geometrytype(\"%s\"::geometry)",
-                       state->geo_col_name, state->geo_col_name, state->geo_col_name, state->schema, state->table, state->geo_col_name);
+                       sprintf(query, "SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\".\"%s\" GROUP BY 3",
+                       state->geo_col_name, state->geo_col_name, state->schema, state->table);
                }
                else
                {
                        query = malloc(150 + 4 * strlen(state->geo_col_name) + strlen(state->table));
 
-                       sprintf(query, "SELECT count(\"%s\"), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\" GROUP BY geometrytype(\"%s\"::geometry)",
-                       state->geo_col_name, state->geo_col_name, state->geo_col_name, state->table, state->geo_col_name);
+                       sprintf(query, "SELECT count(1), max(ST_zmflag(\"%s\"::geometry)), geometrytype(\"%s\"::geometry) FROM \"%s\" GROUP BY 3",
+                       state->geo_col_name, state->geo_col_name, state->table);
                }
        }
        else
@@ -955,9 +955,14 @@ getTableInfo(SHPDUMPERSTATE *state)
 
                for (i = 0; i < PQntuples(res); i++)
                {
-                       geometry_type_from_string(PQgetvalue(res, i, 2), &type, &dummy, &dummy);
+                       /* skip null geometries */
+                       if (PQgetisnull(res, i, 2))
+                       {
+                               state->rowcount += atoi(PQgetvalue(res, i, 0));
+                               continue;
+                       }
 
-                       if (!type) continue; /* skip null geometries */
+                       geometry_type_from_string(PQgetvalue(res, i, 2), &type, &dummy, &dummy);
 
                        /* We can always set typefound to that of the first column found */
                        if (!typefound)
index 0a474b17af5baaabba1744457fd085d595013eed..bebef6444053728ecbbc8bd2215239bd7244b5da 100644 (file)
@@ -4608,7 +4608,7 @@ CREATE OR REPLACE FUNCTION ST_AsGeoJson(geom geometry, maxdecimaldigits int4 DEF
        _COST_LOW;
 
 -- Availability: 3.0.0
-CREATE OR REPLACE FUNCTION ST_AsGeoJson(r record, geom_column text DEFAULT '', maxdecimaldigits int4 DEFAULT 15, pretty_print bool DEFAULT false)
+CREATE OR REPLACE FUNCTION ST_AsGeoJson(r record, geom_column text DEFAULT '', maxdecimaldigits int4 DEFAULT 15, pretty_bool bool DEFAULT false)
        RETURNS text
        AS 'MODULE_PATHNAME','ST_AsGeoJsonRow'
        LANGUAGE 'c' STABLE STRICT _PARALLEL