When creating a table in PostgreSQL, default constraint names are assigned if they are not specified:
CREATE TABLE example ( a integer, b integer, UNIQUE (a, b) );
But using ALTER TABLE to add a constraint, it seems that the name is required:
ALTER TABLE example ADD CONSTRAINT my_explicit_constraint_name UNIQUE (a, b);
This caused some inconsistencies in the names of the projects that I worked on, and offers the following questions:
Is there an easy way to add a constraint to an existing table with the name that it would get if it were added when the table was created?
If not, should the default names be excluded at all to prevent inconsistencies?
postgresql naming-conventions constraints
Ian Mackinnon Nov 05 '10 at 16:30 2010-11-05 16:30
source share