From f1b475ddcbea7951a7ef825f137abdc54e5a34e4 Mon Sep 17 00:00:00 2001 From: Lukas Fittl Date: Fri, 9 Jun 2023 19:10:25 -0700 Subject: [PATCH] Deparser: Correctly quote identifier in ALTER TABLE ... ADD CONSTRAINT [x] --- src/postgres_deparse.c | 2 +- test/deparse_tests.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/postgres_deparse.c b/src/postgres_deparse.c index 8687a9d3..c24533cc 100644 --- a/src/postgres_deparse.c +++ b/src/postgres_deparse.c @@ -4593,7 +4593,7 @@ static void deparseConstraint(StringInfo str, Constraint *constraint) if (constraint->conname != NULL) { appendStringInfoString(str, "CONSTRAINT "); - appendStringInfoString(str, constraint->conname); + appendStringInfoString(str, quote_identifier(constraint->conname)); appendStringInfoChar(str, ' '); } diff --git a/test/deparse_tests.c b/test/deparse_tests.c index 3c203615..106f2349 100644 --- a/test/deparse_tests.c +++ b/test/deparse_tests.c @@ -392,6 +392,7 @@ const char* tests[] = { "CREATE INDEX \"foo.index\" ON foo USING btree (bar)", "CREATE TABLE distributors (did int, name varchar(40), UNIQUE (name) WITH (fillfactor=70)) WITH (fillfactor=70)", "SHOW ALL", + "ALTER TABLE ONLY public.\"Test 123\" ADD CONSTRAINT \"Test 123_pkey\" PRIMARY KEY (c1)", }; size_t testsLength = __LINE__ - 4;