From b66f9eff1fe64674cac65b858412a1645b5549c3 Mon Sep 17 00:00:00 2001 From: Lukas Fittl Date: Sat, 25 Feb 2023 23:42:16 -0800 Subject: [PATCH] Deparser: Ensure index names are quoted as identifiers Fixes https://github.com/pganalyze/pg_query_go/issues/77 --- src/pg_query_deparse.c | 2 +- test/deparse_tests.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pg_query_deparse.c b/src/pg_query_deparse.c index 3afafc61..ff3069f1 100644 --- a/src/pg_query_deparse.c +++ b/src/pg_query_deparse.c @@ -7938,7 +7938,7 @@ static void deparseIndexStmt(StringInfo str, IndexStmt *index_stmt) if (index_stmt->idxname != NULL) { - appendStringInfoString(str, index_stmt->idxname); + appendStringInfoString(str, quote_identifier(index_stmt->idxname)); appendStringInfoChar(str, ' '); } diff --git a/test/deparse_tests.c b/test/deparse_tests.c index 49b03e91..0a63a3c0 100644 --- a/test/deparse_tests.c +++ b/test/deparse_tests.c @@ -387,6 +387,7 @@ const char* tests[] = { "ALTER TABLE ALL IN TABLESPACE foo OWNED BY bar, quux SET TABLESPACE fred NOWAIT", "MERGE INTO measurement m USING new_measurement nm ON m.city_id = nm.city_id AND m.logdate = nm.logdate WHEN MATCHED AND nm.peaktemp IS NULL THEN DELETE WHEN MATCHED THEN UPDATE SET peaktemp = GREATEST(m.peaktemp, nm.peaktemp), unitsales = m.unitsales + COALESCE(nm.unitsales, 0) WHEN NOT MATCHED THEN INSERT (city_id, logdate, peaktemp, unitsales) VALUES (city_id, logdate, peaktemp, unitsales)", "COPY vistest FROM STDIN FREEZE CSV", + "CREATE INDEX \"foo.index\" ON foo USING btree (bar)", }; size_t testsLength = __LINE__ - 4;