From 0219f550718afd97127fe8c218fdfb1f85aec558 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Sat, 1 Apr 2017 22:37:26 +0200 Subject: [PATCH] Review DROP INDEX objects quoting. Force double-quoting of objects name in DROP INDEX commands by using the format directive ~s. The names of the objects we are dropping usually come from a PostgreSQL catalog, but still might contain force-quote conditions like starting with a number, as shown in #530. This fix certainly means we will have to review all the DDL formatting we do in pgloader and apply a single method of quoting all along. The simpler one is of course to force quote every object name in "", but it might not be the smartest one (what if some sources are sending already quoted object names, that needs a check), and it's certainly not the prettier way to go at it: people usually like to avoid unnecessary quotes, calling them clutter. Fix #530. --- src/pgsql/pgsql-ddl.lisp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pgsql/pgsql-ddl.lisp b/src/pgsql/pgsql-ddl.lisp index 9faeb64..4e087b4 100644 --- a/src/pgsql/pgsql-ddl.lisp +++ b/src/pgsql/pgsql-ddl.lisp @@ -198,15 +198,19 @@ ;; here always quote the constraint name, currently the name ;; comes from one source only, the PostgreSQL database catalogs, ;; so don't question it, quote it. + ;; + ;; The constraint name could begin with numbers of follow other + ;; force-quoting PostgreSQL rules, so we really quote it (using + ;; ~s here). (format stream - "ALTER TABLE ~a DROP CONSTRAINT~:[~; IF EXISTS~] ~a~@[ CASCADE~];" + "ALTER TABLE ~a DROP CONSTRAINT~:[~; IF EXISTS~] ~s~@[ CASCADE~];" (format-table-name (index-table index)) if-exists (index-conname index) cascade)) (t - (format stream "DROP INDEX~:[~; IF EXISTS~] ~@[~a.~]~a~@[ CASCADE~];" + (format stream "DROP INDEX~:[~; IF EXISTS~] ~@[~s.~]~s~@[ CASCADE~];" if-exists schema-name index-name cascade)))))