Du kan forespørge i systemkataloget pg_constraint
, f.eks.:
select consrc
from pg_constraint
where conrelid = 'requests'::regclass
and consrc like '(status%';
consrc
---------------------------------------------------------------------------
(status = ANY (ARRAY['pending'::text, 'success'::text, 'failure'::text]))
(1 row)
Brug følgende funktion til at pakke ud strengen:
create or replace function get_check_values(str text)
returns setof text language plpgsql as $$
begin
return query
execute format (
'select * from unnest(%s)',
regexp_replace(str, '.*(ARRAY\[.*\]).*', '\1'));
end $$;
select get_check_values(consrc)
from pg_constraint
where conrelid = 'requests'::regclass
and consrc like '(status%';
get_check_values
------------------
pending
success
failure
(3 rows)