Вы можете использовать системные каталоги pg_constraint
и pg_description
для запроса комментариев к ограничениям.
Пример таблицы с комментариями к ограничениям:
create table test(
id int unique,
str text check(str <> '')
);
comment on constraint test_id_key on test is 'my comment on test_id_key';
comment on constraint test_str_check on test is 'my comment on test_str_check';
Выбрать все комментарии к ограничениям таблицы test
:
select c.relname, t.conname, d.description
from pg_class c
join pg_constraint t on c.oid = t.conrelid
join pg_description d on t.oid = d.objoid and t.tableoid = d.classoid
where c.relname = 'test'
relname | conname | description
---------+----------------+------------------------------
test | test_str_check | my comment on test_str_check
test | test_id_key | my comment on test_id_key
(2 rows)