开发者

How to get the name of a unique constraint in postgresql?

开发者 https://www.devze.com 2023-03-23 00:41 出处:网络
I need to drop a unique constraint from a pos开发者_开发问答tgresql table, but I didn\'t give it a name in the schema. Does anybody know, how to get the name of such a constraint, or how to drop it?Th

I need to drop a unique constraint from a pos开发者_开发问答tgresql table, but I didn't give it a name in the schema. Does anybody know, how to get the name of such a constraint, or how to drop it?


That is something like (for single column constaint):

tableName_columnName_key

To get constaint name write (in psql):

\d tableName

or use pg_constraint system catalog:

SELECT conname
FROM pg_constraint
WHERE conrelid =
    (SELECT oid 
    FROM pg_class
    WHERE relname LIKE 'tableName');

Also you can get it from pgAdmin in objects tree.


SELECT conname
FROM pg_constraint
WHERE conrelid = 'mytable'::regclass::oid
0

精彩评论

暂无评论...
验证码 换一张
取 消