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.
This commit is contained in:
Dimitri Fontaine 2017-04-01 22:37:26 +02:00
parent e2bc7e4fd4
commit 0219f55071

View File

@ -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)))))