Możesz wysłać zapytanie do katalogu systemowego pg_constraint
, np.:
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)
Użyj poniższej funkcji, aby rozpakować ciąg:
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)