从系统目录中获取数据类型

时间:2016-11-16 16:56:20

标签: sql postgresql

我正在尝试获取数据类型的名称,这些名称在系统目录的列描述中使用。

我正确地完成了这项任务吗?

select data_type
from information_schema.columns
group by data_type;

感谢您的时间。

1 个答案:

答案 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;