I applied a constraint but forgot its name. Now I want to drop it using ALTER TABLE [TABLENAME] DROP CONSTRAINT [CONSTRAINTNAME]. If there is a way to drop all constraint from a column that should work too.
I cannot use a psql command.
Asked
Active
Viewed 5,427 times
2
Paul White
- 94,921
- 30
- 437
- 687
No Name
- 25
- 1
- 6
1 Answers
3
PostgreSQL exposes the constraints as well as other schema details through information_schema, so to find all the constraints for the table, query table_constraints, for example:
SELECT constraint_name FROM information_schema.table_constraints
WHERE table_name='my_table' AND constraint_type='UNIQUE';
To find which columns are involved into the constraints, check constraint_column_usage.
bereal
- 148
- 1
- 5