- This controls the inheritance semantics. If turned off>,
- subtables are not accessed by various commands by default; basically
- an implied ONLY key word. This was added for
- compatibility with releases prior to 7.1. See
- for more information.
+ This setting controls whether undecorated table references are
+ considered to include inheritance child tables. The default is
+ on>, which means child tables are included (thus,
+ a *> suffix is assumed by default). If turned
+ off>, child tables are not included (thus, an
+ ONLY prefix is assumed). The SQL standard
+ requires child tables to be included, so the off> setting
+ is not spec-compliant, but it is provided for compatibility with
+
PostgreSQL> releases prior to 7.1.
+ See for more information.
+
+
+ Turning sql_inheritance> off is deprecated, because that
+ behavior has been found to be error-prone as well as contrary to SQL
+ standard. Discussions of inheritance behavior elsewhere in this
+ manual generally assume that it is on>.
ONLY keyword.
+ You can also write the table name with a trailing *>
+ to explicitly specify that descendant tables are included:
+
+SELECT name, altitude
+ FROM cities*
+ WHERE altitude > 500;
+
+
+ Writing *> is not necessary, since this behavior is
+ the default (unless you have changed the setting of the
+ configuration option).
+ However writing *> might be useful to emphasize that
+ additional tables will be searched.
+
+
In some cases you might wish to know which table a particular row
originated from. There is a system column called
data modification, or schema modification
(e.g., SELECT, UPDATE, DELETE,
most variants of ALTER TABLE, but
- not INSERT and ALTER TABLE ...
+ not INSERT or ALTER TABLE ...
RENAME) typically default to including child tables and
support the ONLY notation to exclude them.
Commands that do database maintenance and tuning
(e.g., REINDEX, VACUUM)
- typically only work on individual, physical tables and do no
+ typically only work on individual, physical tables and do not
support recursing over inheritance hierarchies. The respective
- behavior of each individual command is documented in the reference
- part ().
+ behavior of each individual command is documented in its reference
+ page ().
inheritance is useful for your application.
-
-
Deprecated
- In releases of
PostgreSQL prior to 7.1, the
- default behavior was not to include child tables in queries. This was
- found to be error prone and also in violation of the SQL
- standard. You can get the pre-7.1 behavior by turning off the
- configuration
- option.
-
-
-
— any columns added in subtables are ignored.
+ Instead of writing ONLY> before the table name, you can write
+ *> after the table name to explicitly specify that descendant
+ tables are included. Writing *> is not necessary since that
+ behavior is the default (unless you have changed the setting of the
+ linkend="guc-sql-inheritance"> configuration option). However writing
+ *> might be useful to emphasize that additional tables will be
+ searched.
+
+
Joined Tables
name
- The name (possibly schema-qualified) of an existing table to
- alter. If ONLY> is specified, only that table is
- altered. If ONLY> is not specified, the table and any
- descendant tables are altered.
+ The name (optionally schema-qualified) of an existing table to
+ alter. If ONLY> is specified before the table name, only
+ that table is altered. If ONLY> is not specified, the table
+ and all its descendant tables (if any) are altered. Optionally,
+ *> can be specified after the table name to explicitly
+ indicate that descendant tables are included.
- To remove a check constraint from a table only:
+ To remove a check constraint from one table only:
ALTER TABLE ONLY distributors DROP CONSTRAINT zipchk;
-DELETE FROM [ ONLY ] table [ [ AS ] alias ]
+DELETE FROM [ ONLY ] table [ * ] [ [ AS ] alias ]
[ USING using_list ]
[ WHERE condition | WHERE CURRENT OF cursor_name ]
[ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]
- By default, DELETE will delete rows in the
- specified table and all its child tables. If you wish to delete only
- from the specific table mentioned, you must use the
- ONLY clause.
-
-
There are two ways to delete rows in a table using information
contained in other tables in the database: using sub-selects, or
Parameters
-
- ONLY>
-
- If specified, delete rows from the named table only. When not
- specified, any tables inheriting from the named table are also processed.
-
-
-
-
table
- The name (optionally schema-qualified) of an existing table.
+ The name (optionally schema-qualified) of the table to delete rows
+ from. If ONLY> is specified before the table name,
+ matching rows are deleted from the named table only. If
+ ONLY> is not specified, matching rows are also deleted
+ from any tables inheriting from the named table. Optionally,
+ *> can be specified after the table name to explicitly
+ indicate that descendant tables are included.
-LOCK [ TABLE ] [ ONLY ] name [, ...] [ IN lockmode MODE ] [ NOWAIT ]
+LOCK [ TABLE ] [ ONLY ] name [ * ] [, ...] [ IN lockmode MODE ] [ NOWAIT ]
where lockmode is one of:
The name (optionally schema-qualified) of an existing table to
- lock. If ONLY> is specified, only that table is
- locked. If ONLY> is not specified, the table and all
- its descendant tables (if any) are locked.
+ lock. If ONLY> is specified before the table name, only that
+ table is locked. If ONLY> is not specified, the table and all
+ its descendant tables (if any) are locked. Optionally, *>
+ can be specified after the table name to explicitly indicate that
+ descendant tables are included.
table_name
- The name (optionally schema-qualified) of an existing table or
- view. If ONLY> is specified, only that table is
- scanned. If ONLY> is not specified, the table and
- any descendant tables are scanned.
+ The name (optionally schema-qualified) of an existing table or view.
+ If ONLY> is specified before the table name, only that
+ table is scanned. If ONLY> is not specified, the table
+ and all its descendant tables (if any) are scanned. Optionally,
+ *> can be specified after the table name to explicitly
+ indicate that descendant tables are included.
-
ONLY and Parentheses
+
ONLY and Inheritance
- The SQL standard requires parentheses around the table name
- after ONLY, as in SELECT * FROM ONLY
- (tab1), ONLY (tab2) WHERE .... PostgreSQL supports that
- as well, but the parentheses are optional. (This point applies
- equally to all SQL commands supporting the ONLY
- option.)
+ The SQL standard requires parentheses around the table name when
+ writing ONLY, for example SELECT * FROM ONLY
+ (tab1), ONLY (tab2) WHERE ....
PostgreSQL>
+ considers these parentheses to be optional.
+
+
+
PostgreSQL> allows a trailing *> to be written to
+ explicitly specify the non-ONLY behavior of including
+ child tables. The standard does not allow this.
+
+
+ (These points apply equally to all SQL commands supporting the
+ ONLY option.)
-TRUNCATE [ TABLE ] [ ONLY ] name [, ... ]
+TRUNCATE [ TABLE ] [ ONLY ] name [ * ] [, ... ]
[ RESTART IDENTITY | CONTINUE IDENTITY ] [ CASCADE | RESTRICT ]
name
- The name (optionally schema-qualified) of a table to be
- truncated. If ONLY> is specified, only that table is
- truncated. If ONLY> is not specified, the table and
- all its descendant tables (if any) are truncated.
+ The name (optionally schema-qualified) of a table to truncate.
+ If ONLY> is specified before the table name, only that table
+ is truncated. If ONLY> is not specified, the table and all
+ its descendant tables (if any) are truncated. Optionally, *>
+ can be specified after the table name to explicitly indicate that
+ descendant tables are included.
-UPDATE [ ONLY ] table [ [ AS ] alias ]
+UPDATE [ ONLY ] table [ * ] [ [ AS ] alias ]
SET { column = { expression | DEFAULT } |
( column [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...]
[ FROM from_list ]
columns not explicitly modified retain their previous values.
- By default, UPDATE will update rows in the
- specified table and all its subtables. If you wish to only update
- the specific table mentioned, you must use the ONLY>
- clause.
-
-
There are two ways to modify a table using information contained in
other tables in the database: using sub-selects, or specifying
The name (optionally schema-qualified) of the table to update.
+ If ONLY> is specified before the table name, matching rows
+ are updated in the named table only. If ONLY> is not
+ specified, matching rows are also updated in any tables inheriting from
+ the named table. Optionally, *> can be specified after the
+ table name to explicitly indicate that descendant tables are included.