Skip to content

Instantly share code, notes, and snippets.

@hooopo
Created February 19, 2019 08:44
Show Gist options
  • Save hooopo/9dfc20943a23b4f5082fa492035a92a9 to your computer and use it in GitHub Desktop.
Save hooopo/9dfc20943a23b4f5082fa492035a92a9 to your computer and use it in GitHub Desktop.
\copy (SELECT row_number() over() AS "序号", n.nspname AS "系统名", c.relname AS "英文表名", d.description AS "字段中文名", a.attname AS "字段英文名", format_type(a.atttypid, a.atttypmod) AS "数据类型", a.attnotnull as "是否为空", coalesce(i.indisprimary, false) AS "是否主键", def.adsrc AS "默认值" FROM pg_attribute a LEFT JOIN pg_class c ON a.attrelid = c.oid LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_description d ON (c.oid = d.objoid AND a.attnum = d.objsubid) LEFT JOIN pg_index i ON (c.oid = i.indrelid AND i.indkey[0] = a.attnum) LEFT JOIN pg_attrdef def ON (a.attrelid = def.adrelid AND a.attnum = def.adnum) WHERE c.relkind in ('r', '') AND pg_catalog.pg_table_is_visible(c.oid) AND n.nspname != 'pg_catalog' AND n.nspname != 'information_schema' AND n.nspname != 'public' AND n.nspname !~ '^pg_toast' AND a.attname NOT IN ('cid', 'xid', 'xmin', 'xmax', 'cmin', 'cmax', 'ctid', 'tableoid') ORDER BY 2,3) to '~/columns.csv' with csv header;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment