zdsg
发布于

OushuDB查看一张表的所有字段并拼接起来

select string_agg(a.attname,',' order by a.attnum)
from pg_catalog.pg_attribute a
inner join
pg_catalog.pg_class c on a.attrelid=c.oid
inner join
pg_catalog.pg_namespace n on n.oid = c.relnamespace
where a.attnum>0 AND NOT a.attisdropped and n.nspname='public' and c.relname=lower('table_name');
评论(1)
test