pg_tables

列出当前数据库中所有表的系统视图

pg_tables 是一个列出当前数据库中可用表的系统目录视图。

pg_tables 添加于PostgreSQL 6.4

按 PostgreSQL 版本定义

pg_tables (PostgreSQL 17)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 16)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 15)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 14)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 13)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 12)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 11)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 10)

              View "pg_catalog.pg_tables"
   Column    |  Type   | Collation | Nullable | Default 
-------------+---------+-----------+----------+---------
 schemaname  | name    |           |          | 
 tablename   | name    |           |          | 
 tableowner  | name    |           |          | 
 tablespace  | name    |           |          | 
 hasindexes  | boolean |           |          | 
 hasrules    | boolean |           |          | 
 hastriggers | boolean |           |          | 
 rowsecurity | boolean |           |          |
    

文档: pg_tables

pg_tables (PostgreSQL 9.6)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean | 
 rowsecurity | boolean |
    

文档: pg_tables

pg_tables (PostgreSQL 9.5)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean | 
 rowsecurity | boolean |
    

文档: pg_tables

pg_tables (PostgreSQL 9.4)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean |
    

文档: pg_tables

pg_tables (PostgreSQL 9.3)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean |
    

文档: pg_tables

pg_tables (PostgreSQL 9.2)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean |
    

文档: pg_tables

pg_tables (PostgreSQL 9.1)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean |
    

文档: pg_tables

pg_tables (PostgreSQL 9.0)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean |
    

文档: pg_tables

pg_tables (PostgreSQL 8.4)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean | 
View definition:
 SELECT n.nspname AS schemaname, c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relhasrules AS hasrules, c.relhastriggers AS hastriggers
   FROM pg_class c
   LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
   LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
  WHERE c.relkind = 'r'::"char";
    

文档: pg_tables

pg_tables (PostgreSQL 8.3)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean | 
View definition:
 SELECT n.nspname AS schemaname, c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relhasrules AS hasrules, c.reltriggers > 0 AS hastriggers
   FROM pg_class c
   LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
   LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
  WHERE c.relkind = 'r'::"char";
    

文档: pg_tables

pg_tables (PostgreSQL 8.2)

    View "pg_catalog.pg_tables"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 schemaname  | name    | 
 tablename   | name    | 
 tableowner  | name    | 
 tablespace  | name    | 
 hasindexes  | boolean | 
 hasrules    | boolean | 
 hastriggers | boolean | 
View definition:
 SELECT n.nspname AS schemaname, c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, t.spcname AS "tablespace", c.relhasindex AS hasindexes, c.relhasrules AS hasrules, c.reltriggers > 0 AS hastriggers
   FROM pg_class c
   LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
   LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
  WHERE c.relkind = 'r'::"char";
    

文档: pg_tables

更改历史记录

示例

在空数据库中在 public 模式下创建表后,来自 pg_tables 的示例行

postgres=# CREATE TABLE foo (id INT, val TEXT);
CREATE TABLE

postgres=# SELECT * FROM pg_tables WHERE schemaname = 'public'\gx
-[ RECORD 1 ]---------
schemaname  | public
tablename   | foo
tableowner  | postgres
tablespace  | 
hasindexes  | f
hasrules    | f
hastriggers | f
rowsecurity | f

分类

系统目录

另请参见

pg_classpg_views

反馈

提交任何关于 "pg_tables" 的评论、建议或更正 此处