TABLE

A DQL command for selecting all rows from a table

TABLE is a DQL command for selecting all rows from a table, effectively an alias for SELECT * FROM table.

TABLE was added in PostgreSQL 8.4.

Change history

Examples

Basic execution of TABLE:

postgres=# \d foo
                Table "public.foo"
 Column |  Type   | Collation | Nullable | Default
--------+---------+-----------+----------+---------
 id     | integer |           |          |

postgres=# SELECT COUNT(*) FROM foo;
 count
-------
     1
(1 row)

postgres=# TABLE foo;
 id
----
  1
(1 row)

TABLE can be used in parts of a SELECT statement:

postgres=# WITH bar AS (TABLE foo) SELECT * FROM bar;
 id
----
  1
(1 row)

TABLE cannot be combined with a WHERE clause:

postgres=# TABLE foo WHERE id > 1;
ERROR:  syntax error at or near "WHERE"
LINE 1: TABLE foo WHERE id > 1

but can be used with WITH, UNION, INTERSECT, EXCEPT, ORDER BY, LIMIT, OFFSET, FETCH { FIRST | NEXT } and FOR action, e.g.:

postgres=# WITH bar AS (TABLE foo UNION ALL TABLE foo) TABLE bar ORDER BY id LIMIT 1;
 id
----
  1
(1 row)
  • PostgreSQL documentation: TABLE

Categories

DQL, SQL command

See also

SELECT