我正在尝试获取数据类型的名称,这些名称在系统目录的列描述中使用。
我正确地完成了这项任务吗?
select data_type
from information_schema.columns
group by data_type;
感谢您的时间。
答案 0 :(得分:0)
出于好奇(因为我已经在这里有源代码),我看了一眼,发现函数\dT
中的src/bin/psql/describe.c
生成了describeTypes
等效的查询
例如\dTS
就像:
SELECT n.nspname AS "Schema",
pg_catalog.format_type(t.oid, NULL) as "Name",
pg_catalog.obj_description(t.oid, 'pg_type') as "Description"
FROM pg_catalog.pg_type t
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
WHERE (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid))
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND n.nspname <> 'information_schema'
ORDER BY 1, 2;