[postgis-tickets] r17642 - Handle NULL geometry values in pgsql2shp
Paul Ramsey
pramsey at cleverelephant.ca
Mon Jul 29 09:45:15 PDT 2019
Author: pramsey
Date: 2019-07-29 09:45:15 -0700 (Mon, 29 Jul 2019)
New Revision: 17642
Modified:
branches/2.4/NEWS
branches/2.4/loader/pgsql2shp-core.c
Log:
Handle NULL geometry values in pgsql2shp
References #4209
Modified: branches/2.4/NEWS
===================================================================
--- branches/2.4/NEWS 2019-07-29 16:45:09 UTC (rev 17641)
+++ branches/2.4/NEWS 2019-07-29 16:45:15 UTC (rev 17642)
@@ -11,6 +11,7 @@
- #4440, Internal type lookups fail over FDW (Paul Ramsey)
- #4445, Fix bug in lwgeom_le (Raúl Marín)
- #4466, Fix undefined behaviour in _postgis_gserialized_stats (Raúl Marín)
+ - #4209, Handle NULL geometry values in pgsql2shp (Paul Ramsey)
PostGIS 2.4.7
Modified: branches/2.4/loader/pgsql2shp-core.c
===================================================================
--- branches/2.4/loader/pgsql2shp-core.c 2019-07-29 16:45:09 UTC (rev 17641)
+++ branches/2.4/loader/pgsql2shp-core.c 2019-07-29 16:45:15 UTC (rev 17642)
@@ -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;
More information about the postgis-tickets
mailing list