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
更改历史记录
- PostgreSQL 9.5
- 添加了列
hasrowsecurity
(提交 491c029d)
- 添加了列
- PostgreSQL 8.0
- 添加了列
tablespace
(提交 4690cc9c)
- 添加了列
- PostgreSQL 7.3
- 添加了列
schemaname
(提交 3b78826b)
- 添加了列
- PostgreSQL 6.4
- 添加 (提交 f93b6974)
示例
在空数据库中在 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
参考文献
- PostgreSQL 文档: pg_tables