/
telnov.ob
/
postgresql-patterns-library
Обзор
Документация
Войти
/
telnov.ob
/
postgresql-patterns-library
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
functions/table_description.sql
50 строк
1 KB
rin-nas
old pg10 comment removed
13 апр 2026, 11:45
13 апр 2026, 11:45
233b866
Код
Авторство
О чём код?
create or replace function public.table_description( table_name regclass, new_description text default null ) returns text volatile --COMMENT is not allowed in a non-volatile function --returns null on null input parallel safe language plpgsql set search_path = '' as $$ declare rec record; query text not null default 'comment on table %I.%I is %L'; begin if table_name is null then return null; elsif new_description is null then return obj_description(table_name, 'pg_class'); end if; SELECT ns.nspname as table_schema, c.relname as table_name INTO rec FROM pg_catalog.pg_class AS c JOIN pg_catalog.pg_namespace AS ns ON c.relnamespace = ns.oid WHERE c.oid = table_name; query := format(query, rec.table_schema, rec.table_name, new_description); --raise notice '%', query; execute query; return new_description; end; $$; comment on function public.table_description is 'Get or set table description, like COMMENT ON TABLE command, but it can set description dynamically'; --TEST do $$ begin create schema if not exists test; create table test.d(); assert public.table_description('test.d'::regclass) is null; --GET assert public.table_description('test.d'::regclass, 'table''d') = 'table''d'; --SET drop table test.d; end $$;