[SCM] PostGIS branch stable-3.6 updated. 3.6.2-7-ge5be73640

git at osgeo.org git at osgeo.org
Tue Mar 17 13:25:41 PDT 2026


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.6 has been updated
       via  e5be73640efdd333ed6358c442233d269f2dbc5f (commit)
       via  87e77f3e5b78585cb764fe72893ba6a826e4fc1e (commit)
      from  4d03e7a845341dcbc3a2606dc7439d6f9a378b84 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit e5be73640efdd333ed6358c442233d269f2dbc5f
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Tue Mar 17 13:25:33 2026 -0700

    NEWS item for GH-850

diff --git a/NEWS b/NEWS
index ab8ac0c4e..6c776454a 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,7 @@ topogeometry corruption:
 - #6055, Remove rare extension priv escalation case.
          Reported by Sven Klemm (Tiger Data), Allistair Ishmael Hakim (allistair.sh)
          and Daniel Bakker
+- GH-850 Use quote_identifier to build tables in pgis_tablefromflatgeobuf (Ariel Mashraki)
 
 
 PostGIS 3.6.2

commit 87e77f3e5b78585cb764fe72893ba6a826e4fc1e
Author: Ariel Mashraki <ariel at mashraki.co.il>
Date:   Tue Mar 17 13:41:59 2026 +0200

    Use quote_identifier to build tables in pgis_tablefromflatgeobuf

diff --git a/postgis/lwgeom_in_flatgeobuf.c b/postgis/lwgeom_in_flatgeobuf.c
index 8435cd14e..97ed26b16 100644
--- a/postgis/lwgeom_in_flatgeobuf.c
+++ b/postgis/lwgeom_in_flatgeobuf.c
@@ -75,13 +75,9 @@ Datum pgis_tablefromflatgeobuf(PG_FUNCTION_ARGS)
 	char *schema;
 	text *table_input;
 	char *table;
-	char *format;
-	char *sql;
 	bytea *data;
 	uint16_t i;
-	char **column_defs;
-	size_t column_defs_total_len;
-	char *column_defs_str;
+	StringInfoData sql;
 
 	if (PG_ARGISNULL(0))
 		PG_RETURN_NULL();
@@ -107,48 +103,34 @@ Datum pgis_tablefromflatgeobuf(PG_FUNCTION_ARGS)
 	flatgeobuf_check_magicbytes(ctx);
 	flatgeobuf_decode_header(ctx->ctx);
 
-	column_defs = palloc(sizeof(char *) * ctx->ctx->columns_size);
-	column_defs_total_len = 0;
+	initStringInfo(&sql);
+	appendStringInfo(&sql, "create table %s.%s (id int, geom geometry",
+		quote_identifier(schema), quote_identifier(table));
+
 	POSTGIS_DEBUGF(2, "found %d columns", ctx->ctx->columns_size);
 	for (i = 0; i < ctx->ctx->columns_size; i++) {
 		flatgeobuf_column *column = ctx->ctx->columns[i];
 		const char *name = column->name;
 		uint8_t column_type = column->type;
 		char *pgtype = get_pgtype(column_type);
-		size_t len = strlen(name) + 1 + strlen(pgtype) + 1;
-		column_defs[i] = palloc0(sizeof(char) * len);
-		strcat(column_defs[i], name);
-		strcat(column_defs[i], " ");
-		strcat(column_defs[i], pgtype);
-		column_defs_total_len += len;
-	}
-	column_defs_str = palloc0(sizeof(char) * column_defs_total_len + (ctx->ctx->columns_size * 2) + 2 + 1);
-	if (ctx->ctx->columns_size > 0)
-		strcat(column_defs_str, ", ");
-	for (i = 0; i < ctx->ctx->columns_size; i++) {
-		strcat(column_defs_str, column_defs[i]);
-		if (i < ctx->ctx->columns_size - 1)
-			strcat(column_defs_str, ", ");
+		appendStringInfo(&sql, ", %s %s", quote_identifier(name), pgtype);
 	}
 
-	POSTGIS_DEBUGF(2, "column_defs_str %s", column_defs_str);
+	appendStringInfoChar(&sql, ')');
 
-	format = "create table %s.%s (id int, geom geometry%s)";
-	sql = palloc0(strlen(format) + strlen(schema) + strlen(table) + strlen(column_defs_str) + 1);
-
-	sprintf(sql, format, schema, table, column_defs_str);
-
-	POSTGIS_DEBUGF(3, "sql: %s", sql);
+	POSTGIS_DEBUGF(3, "sql: %s", sql.data);
 
 	if (SPI_connect() != SPI_OK_CONNECT)
 		elog(ERROR, "Failed to connect SPI");
 
-	if (SPI_execute(sql, false, 0) != SPI_OK_UTILITY)
+	if (SPI_execute(sql.data, false, 0) != SPI_OK_UTILITY)
 		elog(ERROR, "Failed to create table");
 
 	if (SPI_finish() != SPI_OK_FINISH)
 		elog(ERROR, "Failed to finish SPI");
 
+	pfree(sql.data);
+
 	POSTGIS_DEBUG(3, "finished");
 
 	PG_RETURN_NULL();
diff --git a/regress/core/flatgeobuf.sql b/regress/core/flatgeobuf.sql
index 10a535bc2..df46eca1e 100644
--- a/regress/core/flatgeobuf.sql
+++ b/regress/core/flatgeobuf.sql
@@ -158,6 +158,26 @@ select 'E1', id, bool_1, ST_AsText(geom), bool_2 from ST_FromFlatGeobuf(null::fl
     ) q)
 );
 
+select '--- Quoted identifiers ---';
+
+-- Verify that special characters in column names are properly quoted
+select ST_FromFlatGeobufToTable('public', 'flatgeobuf_qi', (
+    select ST_AsFlatGeobuf(q) from (
+        select null::geometry, null::text as "col name; with special--chars"
+    ) q
+));
+select 'QI1' where exists (
+    select 1 from information_schema.columns
+    where table_schema = 'public'
+      and table_name = 'flatgeobuf_qi'
+      and column_name = 'col name; with special--chars'
+);
+select 'QI2' where exists (
+    select 1 from information_schema.tables
+    where table_schema = 'public' and table_name = 'flatgeobuf_t1'
+);
+
 drop table if exists public.flatgeobuf_t1;
 drop table if exists public.flatgeobuf_a1;
 drop table if exists public.flatgeobuf_e1;
+drop table if exists public.flatgeobuf_qi;
diff --git a/regress/core/flatgeobuf_expected b/regress/core/flatgeobuf_expected
index 61c617de3..c93738ff9 100644
--- a/regress/core/flatgeobuf_expected
+++ b/regress/core/flatgeobuf_expected
@@ -24,3 +24,6 @@ ERROR:  mixed geometry type is not supported
 A1|0||t|1|2|3|4|1.2|1.3|2016-06-23 03:44:52.134125+00|hello
 --- Exotic roundtrips ---
 E1|0|t|POINT(1.1 2.1)|f
+--- Quoted identifiers ---
+QI1
+QI2

-----------------------------------------------------------------------

Summary of changes:
 NEWS                             |  1 +
 postgis/lwgeom_in_flatgeobuf.c   | 40 +++++++++++-----------------------------
 regress/core/flatgeobuf.sql      | 20 ++++++++++++++++++++
 regress/core/flatgeobuf_expected |  3 +++
 4 files changed, 35 insertions(+), 29 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list