Created
June 5, 2019 06:18
-
-
Save hooopo/3503978170ff241914f7383a7a8b90b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\copy (SELECT row_number() over() AS "序号", n.nspname as "系统名", c.relname as "表名",pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as "大小",pg_catalog.obj_description(c.oid, 'pg_class') as "中文名",c.reltuples AS "条数" FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','') AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' AND n.nspname !~ '^pg_toast' AND pg_catalog.pg_table_is_visible(c.oid) ORDER BY 1 DESC,2) to '/tmp/tables.csv' WITH CSV HEADER; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
\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;