I have written my own script to generate a restore SQL file and one of the first tasks to do the restore is delete all the constraints that should be there. (Don't worry, I am limiting my script to ones that exist at the time of the backup.)
Here is a generic code snippet
ALTER TABLE ONLY data DROP CONSTRAINT IF EXISTS data_pkey; Testing it on my own development environment it works as expected. However, running it on the production server that same code throws an error:
ERROR: syntax error at or near "EXISTS" LINE 1: ALTER TABLE ONLY data DROP CONSTRAINT IF EXISTS data_pkey; If the IF EXISTS part is removed and the syntax is:
ALTER TABLE ONLY data DROP CONSTRAINT data_pkey; the script runs without a problem.
I checked postgres.org under the ALTER TABLE section and my syntax is valid.
IF EXISTSwas introduced in Postgres 9.2.