I find myself having to check a couple of hundred tables and add the
primary keys back in, if they don't exist.
While there's a IF NOT EXISTS clause on the DROP statement to drop a
constraint, like a primary key, inexplicably there isn't one on the ALTER
TABLE statement that creates them.
The internet is littered with people asking about this, some going back
years. The responses range from manually checking first, using a DROP IF
EXISTS statement first, to writing various blocks of PL/pgSQL code.
Why doesn't ALTER TABLE ... ADD CONSTRAINT not come with an ALTER TABLE
... ADD CONSTRAINT IF NOT EXISTS variant?
Could one be added?
Just wondering,
rik.