I need to drop a unique constraint from a postgresql 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?
我需要从postgresql表中删除一个唯一约束,但我没有在模式中给它一个名字。有谁知道,如何获得这种约束的名称,或者如何删除它?
2 个解决方案
#1
34
That is something like (for single column constaint):
这就像(对于单列constaint):
tableName_columnName_key
To get constaint name write (in psql):
要获得constaint name write(在psql中):
\d tableName
or use pg_constraint
system catalog:
或使用pg_constraint系统目录:
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.
您也可以从对象树中的pgAdmin获取它。
#2
6
SELECT conname
FROM pg_constraint
WHERE conrelid = 'mytable'::regclass::oid
#1
34
That is something like (for single column constaint):
这就像(对于单列constaint):
tableName_columnName_key
To get constaint name write (in psql):
要获得constaint name write(在psql中):
\d tableName
or use pg_constraint
system catalog:
或使用pg_constraint系统目录:
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.
您也可以从对象树中的pgAdmin获取它。
#2
6
SELECT conname
FROM pg_constraint
WHERE conrelid = 'mytable'::regclass::oid