在PostgreSQL中找到type的定义

时间:2017-08-16 07:28:45

标签: postgresql ddl

我有来自PostgreSQL的表DDL:

Table. ---------------------- 
Type| Freq ----------+----------- 
A | -1 
B | -1 
C | -1 
D | -3 
S | -3 
---------------------- –

那些CREATE TABLE some_table ( id identifier NOT NULL DEFAULT nextval('some_table_id_seq'), center_name common_name NULL, ... ) identifier类型不是标准的PostgreSQL类型。如何找到他们的定义?

1 个答案:

答案 0 :(得分:1)

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 <> 'pg_catalog'
      AND n.nspname <> 'information_schema'
  AND pg_catalog.pg_type_is_visible(t.oid)
ORDER BY 1, 2;