我必須使用我之前直接用 sql 設定的 ESQL/C 在我的 PostgreSQL 中輸出約束。以下是我需要列印的限制。
ALTER TABLE p
ADD CONSTRAINT check_name_of_det
CHECK ((name = 'Screw' AND n_det = 'P6') OR n_det <>'P6');
uj5u.com熱心網友回復:
您可以使用該pg_get_constraintdef功能。引數是來自 的物件 ID pg_constraint。
uj5u.com熱心網友回復:
我將此查詢粘貼到我的原始 ESQL/C 代碼中,但它輸出了一些錯誤而不是此查詢的結果(查詢本身輸出正是我需要的內容 ( CHECK ((((name = 'Screw'::bpchar) AND (n_det = 'P6'::bpchar)) OR (n_det <> 'P6'::bpchar))))。
SELECT pg_get_constraintdef(oid)
FROM pg_constraint
WHERE conrelid='p'::regclass AND contype = 'c';
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/343265.html
標籤:sql PostgreSQL sql
