pg_query显示/描述表

时间:2009-12-21 18:08:42

标签: php postgresql

有没有办法显示所有表格,描述它们并将结果转储到php?

任何想法都将受到赞赏

5 个答案:

答案 0 :(得分:2)

运行psql -E,然后输入所有有趣的\ x命令(如\ dt,\ d table),并阅读它将显示的内容。

答案 1 :(得分:1)

答案 2 :(得分:1)

这是我在psql shell中运行\d时在日志中看到的内容:

SELECT n.nspname as "Schema",
      c.relname as "Name",
      CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
      r.rolname as "Owner"
    FROM pg_catalog.pg_class c
         JOIN pg_catalog.pg_roles r ON r.oid = c.relowner
         LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
    WHERE c.relkind IN ('r','v','S','')
          AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
      AND pg_catalog.pg_table_is_visible(c.oid)
    ORDER BY 1,2;

答案 3 :(得分:0)

您可以从information_schema.tables获取数据。

答案 4 :(得分:0)

还有pg_dump --schema-only