[postgis-tickets] r17639 - Handle NULL geometry values in pgsql2shp
Paul Ramsey
pramsey at cleverelephant.ca
Mon Jul 29 09:32:03 PDT 2019
Author: pramsey
Date: 2019-07-29 09:32:03 -0700 (Mon, 29 Jul 2019)
New Revision: 17639
Modified:
trunk/NEWS
trunk/loader/pgsql2shp-core.c
trunk/postgis/postgis.sql.in
Log:
Handle NULL geometry values in pgsql2shp
References #4209
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2019-07-29 16:30:25 UTC (rev 17638)
+++ trunk/NEWS 2019-07-29 16:32:03 UTC (rev 17639)
@@ -18,6 +18,7 @@
- #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
Modified: trunk/loader/pgsql2shp-core.c
===================================================================
--- trunk/loader/pgsql2shp-core.c 2019-07-29 16:30:25 UTC (rev 17638)
+++ trunk/loader/pgsql2shp-core.c 2019-07-29 16:32:03 UTC (rev 17639)
@@ -887,15 +887,15 @@
{
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,10 +955,15 @@
for (i = 0; i < PQntuples(res); i++)
{
+ /* skip null geometries */
+ if (PQgetisnull(res, i, 2))
+ {
+ state->rowcount += atoi(PQgetvalue(res, i, 0));
+ continue;
+ }
+
geometry_type_from_string(PQgetvalue(res, i, 2), &type, &dummy, &dummy);
- if (!type) continue; /* skip null geometries */
-
/* We can always set typefound to that of the first column found */
if (!typefound)
typefound = type;
Modified: trunk/postgis/postgis.sql.in
===================================================================
--- trunk/postgis/postgis.sql.in 2019-07-29 16:30:25 UTC (rev 17638)
+++ trunk/postgis/postgis.sql.in 2019-07-29 16:32:03 UTC (rev 17639)
@@ -4608,7 +4608,7 @@
_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
More information about the postgis-tickets
mailing list