Contents
TABLE
An SQL command for selecting all rows from a table
TABLE
is an SQL command for selecting all rows with all columns from a table, effectively an alias for SELECT * FROM table
.
TABLE
was added in PostgreSQL 8.4.
Change history
- PostgreSQL 8.4
- added (commit b09a1a29)
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)
References
- PostgreSQL documentation: TABLE
Categories
See also
SELECT