I have to output the constraint in my PostgreSQL using ESQL/C that I have set before directly with sql. Below is my contraint I need to print out.
ALTER TABLE p
ADD CONSTRAINT check_name_of_det
CHECK ((name = 'Screw' AND n_det = 'P6') OR n_det <>'P6');
CodePudding user response:
You can use the pg_get_constraintdef
function. The argument is the object ID from pg_constraint
.
CodePudding user response:
I paste this query to my original ESQL/C code but it outputs something wrong instead of result of this query (The query by itself outputs exact what I need (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';