我试图返回所有使用特定枚举的表。到目前为止,我有这个:
select *
from pg_type t
join pg_enum e on t.oid = e.enumtypid
join pg_catalog.pg_namespace n
ON n.oid = t.typnamespace and t.typname = 'enum';
我该如何修改此查询以返回实际表,还是有其他更好的用法?
答案 0 :(得分:1)
假设您要查找的类型是typschema.typname
,最简单的查询就是:
SELECT t.relnamespace::regnamespace AS schema,
t.relname AS tablename
FROM pg_catalog.pg_class AS t
JOIN pg_catalog.pg_attribute AS c
ON t.oid = c.attrelid
WHERE c.atttypid = 'typschema.typname'::regtype;
答案 1 :(得分:1)
select * from information_schema.columns
where table_schema not in ('information_schema','pg_catalog')
and data_type='enum'