我想删除与表关联的所有外键.
我首先使用下面的方法识别与之关联的外键
SELECT DISTINCT constraint_name
FROM information_schema.key_column_usage
WHERE table_name = 'crm_campaign_offer_customer_groups'
AND table_schema = 'schema001'
AND constraint_name LIKE '%fkey%'
Run Code Online (Sandbox Code Playgroud)
然后使用类似的语句循环遍历每个删除外键
ALTER TABLE crm_campaign_offer_customer_groups DROP CONSTRAINT crm_campaign_offer_customer_groups_variable_1_fkey1;
Run Code Online (Sandbox Code Playgroud)
发生的问题是它首先截断外键表达式然后尝试删除截断的表达式
NOTICE: identifier "..." will be truncated to "..."
ERROR: constraint "..." of relation "..." does not exist
Run Code Online (Sandbox Code Playgroud)
它似乎是截断标识符> 63个字符,但我希望有一个替代,因为表和变量命名约定已经设置
postgresql ×1