Why isn't there a IF NOT EXISTS clause on constraint creation?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Index of Archives]     [Postgresql Home]     [Postgresql General]     [Postgresql Performance]     [Postgresql PHP]     [Postgresql Jobs]     [PHP Users]     [PHP Databases]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Forum]

  Powered by Linux