Updated on 2024-11-05 GMT+08:00

PG_TABLES

PG_TABLES displays access to each table in the database.

Table 1 PG_TABLES columns

Name

Type

Reference

Description

schemaname

name

PG_NAMESPACE.nspname

Name of the schema that contains the table

tablename

name

PG_CLASS.relname

Name of the table

tableowner

name

pg_get_userbyid(PG_CLASS.relowner)

Owner of the table

tablespace

name

PG_TABLESPACE.spcname

Tablespace that contains the table. The default value is null

hasindexes

boolean

PG_CLASS.relhasindex

Whether the table has (or recently had) an index. If it does, its value is true. Otherwise, its value is false.

hasrules

boolean

PG_CLASS.relhasrules

Whether the table has rules. If it does, its value is true. Otherwise, its value is false.

hastriggers

boolean

PG_CLASS.RELHASTRIGGERS

Whether the table has triggers. If it does, its value is true. Otherwise, its value is false.

tablecreator

name

pg_get_userbyid(PG_OBJECT.creator)

Table creator. If the creator has been deleted, no value is returned.

created

timestamp with time zone

PG_OBJECT.ctime

Time when the table was created.

last_ddl_time

timestamp with time zone

PG_OBJECT.mtime

Last time when the cluster was modified.

Example

Query all tables in a specified schema.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
SELECT tablename FROM PG_TABLES WHERE schemaname = 'myschema';
   tablename
----------------
 inventory
 product
 sales_info
 test1
 mytable
 product_info
 customer_info
 newproducts
 customer_t1
(9 rows)