-class="PARAMETER">ETER">ce
"PARreplaceable> [
-class="PARAMETER">log_op ... ]
+WHERE expr ETER">ce"PARreplaceable> [ log_op ... ]
where cond_op can be
1998-09-24
-
+
id="group-by-title">
GROUP BY Clause
of this clause:
GROUP BY column [, ...]
-
- GROUP BY will condense into a single row all rows that share the same values for the
- grouped columns; aggregates return values derived from all rows that make up the group. The value returned for an ungrouped
- and unaggregated column is dependent on the order in which rows happen to be read from the database.
-
-
-
+
+
+
+ GROUP BY will condense into a single row all rows that share the
+ same values for the
+ grouped columns; aggregates return values derived from all rows
+ that make up the group. The value returned for an ungrouped
+ and unaggregated column is dependent on the order in which rows
+ happen to be read from the database.
+
+
+
1998-09-24
-
+
id="having-title">
HAVING Clause
where cond_expr is the same
- as specified for the WHERE clause.
+ as specified for the WHERE clause.
+
HAVING specifies a grouped table derived by the elimination
of groups from the result of the previously specified clause
that do not meet the cond_expr.
-
+
Each column referenced in
-cond_expr shall unambiguously
+ cond_expr shall unambiguously
reference a grouping column.
1998-09-24
-
+
id="order-by-title">
ORDER BY Clause
column can be either a column
- name or an ordinal number.
+ name or an ordinal number.
+
The ordinal numbers refers to the ordinal (left-to-right) position
of the column. This feature makes it possible to define an ordering
- From release 6.4 of PostgreSQL, the columns in the ORDER BY clause do not need to appear in the SELECT clause.
+ From release 6.4 of PostgreSQL, the columns in the ORDER BY clause
+ do not need to appear in the SELECT clause.
Thus the following statement is now legal:
SELECT name FROM distributors ORDER BY code;
-
+
+
Optionally one may add the keyword DESC (descending)
or ASC (ascending) after each column name in the ORDER BY clause.
- If not specified, ASC is assumed by default.
+ If not specified, ASC is assumed by default.
+
1998-09-24
-
+
id="union-title">
UNION Clause
-table_query UNION [ ALL ]
-table_query
- [ ORDER BY column [ ASC | DESC ] [, ...] ]
+table_query UNION [ ALL ] table_query
+ [ ORDER BY column [ ASC | DESC ] [, ...] ]
-
+
where
table_query
- specifies any select expression without an ORDER BY clause.
+ specifies any select expression without an ORDER BY clause.
+
The UNION clause allows the result to be the collection of rows
returned by the queries involved. (See UNION clause).
The two tables that represent the direct operands of the UNION must
have the same number of columns, and corresponding columns must be
- of compatible data types.
+ of compatible data types.
+
By default, the result of UNION does not contain any duplicate rows
- unless the ALL clause is specified.
+ unless the ALL clause is specified.
+
Multiple UNION operators in the same SELECT statement are
evaluated left to right.
Note that the ALL keyword is not global in nature, being
- applied only for the current pair of table results.
-
+ applied only for the current pair of table results.
+
+
1998-09-24
-
+
id="intersect-title">
INTERSECT Clause
-table_query INTERSECT
-table_query
- [ ORDER BY column [ ASC | DESC ] [, ...] ]
+table_query INTERSECT table_query
+ [ ORDER BY column [ ASC | DESC ] [, ...] ]
where
table_query
- specifies any select expression without an ORDER BY clause.
-
+ specifies any select expression without an ORDER BY clause.
+
+
The INTERSECT clause allows the result to be all rows that are
- common to the involved queries. (See INTERSECT clause).
+ common to the involved queries.
The two tables that represent the direct operands of the INTERSECT must
have the same number of columns, and corresponding columns must be
- of compatible data types.
+ of compatible data types.
+
Multiple INTERSECT operators in the same SELECT statement are
evaluated left to right.
-
-
+
1998-09-24
-
+
id="except-title">
EXCEPT Clause
-table_query EXCEPT
- table_query
+table_query EXCEPT table_query
[ ORDER BY column [ ASC | DESC ] [, ...] ]
where
table_query
- specifies any select expression without an ORDER BY clause.
-
+ specifies any select expression without an ORDER BY clause.
+
+
The EXCEPT clause allows the result to be rows from the upper query
that are not in the lower query. (See EXCEPT clause).
The two tables that represent the direct operands of the EXCEPT must
have the same number of columns, and corresponding columns must be
- of compatible data types.
-
+ of compatible data types.
+
+
Multiple EXCEPT operators in the same SELECT statement are
evaluated left to right.
-
-
+
+
-
-
Usage
+
To join the table films with the table
distributors:
-
+
SELECT f.title, f.did, d.name, f.date_prod, f.kind
FROM distributors d, films f
WHERE f.did = d.did
The King and I |109|20th Century Fox|1956-08-11|Musical
Das Boot |110|Bavaria Atelier |1981-11-11|Drama
Bed Knobs and Broomsticks|111|Walt Disney | |Musical
-
+
+
+
To sum the column len of all films and group
the results by kind:
-
+
SELECT kind, SUM(len) AS total FROM films GROUP BY kind;
kind |total
Drama | 14:28
Musical | 06:42
Romantic | 04:38
-
+
+
To sum the column len of all films, group
the results by kind and show those group totals
that are less than 5 hours:
-
+
SELECT kind, SUM(len) AS total
FROM films
GROUP BY kind
----------+------
Comedy | 02:58
Romantic | 04:38
-
+
+
+
- The following two examples are identical ways of sorting the individual
+ The following two examples are identical ways of sorting the individual
results according to the contents of the second column
(name):
-
+
SELECT * FROM distributors ORDER BY name;
SELECT * FROM distributors ORDER BY 2;
111|Walt Disney
112|Warner Bros.
108|Westward
-
+
+
This example shows how to obtain the union of the tables
actors, restricting the results to those that begin
with letter W in each table. Only distinct rows are to be used, so the
ALL keyword is omitted:
-
+
-- distributors: actors:
-- did|name id|name
-- ---+------------ --+--------------
Warren Beatty
Westward
Woody Allen
-
-
+
+
-
-
-
-UNLISTEN
-
-SQL - Language Statements
-
-
-
-UNLISTEN
-
-
-Stop listening for notification
-
-
-
-
-1998-10-19
-
-
-UNLISTEN { notifyname | * }
-
-
-
-
-1998-10-19
-
-
-Inputs
-
-
-
-
-
-notifyname
-
-
-Name of previously registered notify condition.
-
-
-
-
-
-*
-
-
-All current listen registrations for this backend are cleared.
-
-
-
-
-
-
-
-
-
-
-1998-10-19
-
-
-Outputs
-
-
-
-
-
+
+
+
+ UNLISTEN
+
+ SQL - Language Statements
+
+
+
+ UNLISTEN
+
+
+ Stop listening for notification
+
+
+
+
+ 1998-10-19
+
+
+UNLISTEN { notifyname | * }
+
+
+
+
+ 1998-10-19
+
+
+ Inputs
+
+
+
+
+ notifyname
+
+ Name of previously registered notify condition.
+
+
+
+
+ *
+
+ All current listen registrations for this backend are cleared.
+
+
+
+
+
+
+
+
+
+ 1998-10-19
+
+
+ Outputs
+
+
+
+
+
UNLISTEN
-
-
-Acknowledgement that statement has executed.
-
-
-
-
-
-
-
-
-
-
-
-1998-10-19
-
-
-Description
-
-UNLISTEN
-is used to remove an existing NOTIFY registration.
-UNLISTEN cancels any existing registration of the current
-
Postgres session as a listener on the notify
-condition notifyname.
-The special condition wildcard "*" cancels all listener registrations
-for the current session.
-
-
-contains a more extensive
-discussion of the use of LISTEN and
-NOTIFY.
-
-
-
-
-1998-10-19
-
-
-Notes
-
-classname
-needs not to be a valid class name but can be any string valid
-as a name up to 32 characters long.
-
-The backend does not complain if you UNLISTEN something you were not
-listening for.
-Each backend will automatically execute UNLISTEN * when
-exiting.
-
-A restriction in some previous releases of
-classname
-which does not correspond to an actual table must be enclosed in double-quotes
-is no longer present.
-
-
-
-
-
-
-Usage
-
-
+
+
+ Acknowledgement that statement has executed.
+
+
+
+
+
+
+
+
+
+
+ 1998-10-19
+
+
+ Description
+
+
+ UNLISTEN
+ is used to remove an existing NOTIFY registration.
+ UNLISTEN cancels any existing registration of the current
+
Postgres session as a listener on the notify
+ condition notifyname.
+ The special condition wildcard "*" cancels all listener registrations
+ for the current session.
+
+
+
+ contains a more extensive
+ discussion of the use of LISTEN and
+ NOTIFY.
+
+
+
+
+ 1998-10-19
+
+
+ Notes
+
+ classname
+ needs not to be a valid class name but can be any string valid
+ as a name up to 32 characters long.
+
+ The backend does not complain if you UNLISTEN something you were not
+ listening for.
+ Each backend will automatically execute UNLISTEN * when
+ exiting.
+
+ A restriction in some previous releases of
+ classname
+ which does not correspond to an actual table must be enclosed in double-quotes
+ is no longer present.
+
+
+
+
+
+
+ Usage
+
+
+ To subscribe to an existing registration:
+
postgres=> LISTEN virtual;
LISTEN
postgres=> NOTIFY virtual;
NOTIFY
ASYNC NOTIFY of 'virtual' from backend pid '12317' received
-
+
+
+ Once UNLISTEN has been executed, further NOTIFY commands will be
+ ignored:
+
postgres=> UNLISTEN virtual;
UNLISTEN
postgres=> NOTIFY virtual;
NOTIFY
-- notice no NOTIFY event is received
-postgres=>
-
-
-
-
-
-
-Compatibility
-
-
-
-
-1998-10-19
-
-
-SQL92
-
- There is no
UNLISTEN in
SQL92.
-
-
-
-
+
+
+
+
+
+
+ Compatibility
+
+
+
+
+ 1998-10-19
+
+
+ SQL92
+
+ There is no
UNLISTEN in
SQL92.
+
+
+
+
+
+
-
-
-
-UPDATE
-
-SQL - Language Statements
-
-
-
-UPDATE
-
-
-Replaces values of columns in a table
-
-
-
-
-1998-09-24
-
-
-UPDATE table SET column = expression [, ...]
- [ FROM fromlist ]
- [ WHERE condition ]
-
-
-
-
- 1998-09-24
-
-
- Inputs
-
-
-
-
-
- table
-
-
- The name of an existing table.
-
-
-
-
-
- column
-
-
- The name of a column in table.
-
-
-
-
-
- expression
-
-
- A valid expression or value to assign to column.
-
-
-
-
-
- fromlist
-
-
- non-standard extension to allow columns
- from other tables to appear in the WHERE condition.
-
-
-
-
-
- condition
-
-
- Refer to the SELECT statement for a further description
- of the WHERE clause.
-
-
-
-
-
-
-
-
-
- 1998-09-24
-
-
- Outputs
-
-
-
-
-
- UPDATE #
-
-
- Message returned if successful.
- The #
- means the number of rows updated.
- If #
- is equal 0 no rows are updated.
-
-
-
-
-
-
-
-
-
-
- 1998-09-24
-
-
- Description
-
- UPDATE changes the values of the columns specified for
- all rows which satisfy condition. Only the columns
- to be modified need appear as column.
-
- Array references use the same syntax found in SELECT.
- That is, either single array elements, a range of array
- elements or the entire array may be replaced with a single
- query.
-
- You must have write access to the table in order to modify
- it, as well as read access to any table whose values are
- mentioned in the WHERE condition.
-
-
-
-
-
- Usage
-
-
- --Change word "Drama" with "Dramatic" on column kind:
- --
- UPDATE films
- SET kind = 'Dramatic'
- WHERE kind = 'Drama';
-
- SELECT * FROM films WHERE kind = 'Dramatic' OR kind = 'Drama';
+
+
+
+ UPDATE
+
+ SQL - Language Statements
+
+
+
+ UPDATE
+
+
+ Replaces values of columns in a table
+
+
+
+
+ 1998-09-24
+
+
+UPDATE table SET R">colle> = expression [, ...]
+ [ FROM fromlist ]
+ [ WHERE condition ]
+
+
+
+
+ 1998-09-24
+
+
+ Inputs
+
+
+
+
+ table
+
+ The name of an existing table.
+
+
+
+
+ column
+
+ The name of a column in table.
+
+
+
+
+ expression
+
+ A valid expression or value to assign to column.
+
+
+
+
+ fromlist
+
+ non-standard extension to allow columns
+ from other tables to appear in the WHERE condition.
+
+
+
+
+ condition
+
+ Refer to the SELECT statement for a further description
+ of the WHERE clause.
+
+
+
+
+
+
+
+
+
+ 1998-09-24
+
+
+ Outputs
+
+
+
+
+
+UPDATE #
+
+
+ Message returned if successful.
+ The #
+ means the number of rows updated.
+ If #
+ is equal 0 no rows are updated.
+
+
+
+
+
+
+
+
+
+
+ 1998-09-24
+
+
+ Description
+
+ UPDATE changes the values of the columns specified for
+ all rows which satisfy condition. Only the columns
+ to be modified need appear as column.
+
+
+ Array references use the same syntax found in SELECT.
+ That is, either single array elements, a range of array
+ elements or the entire array may be replaced with a single
+ query.
+
+
+ You must have write access to the table in order to modify
+ it, as well as read access to any table whose values are
+ mentioned in the WHERE condition.
+
+
+
+
+
+ Usage
+
+
+ Change word "Drama" with "Dramatic" on column kind:
+
+UPDATE films
+ SET kind = 'Dramatic'
+ WHERE kind = 'Drama';
+SELECT * FROM films WHERE kind = 'Dramatic' OR kind = 'Drama';
code |title |did| date_prod|kind |len
-----+-------------+---+----------+----------+------
M_401|War and Peace|104|1967-02-12|Dramatic | 05:57
T_601|Yojimbo |106|1961-06-16|Dramatic | 01:50
DA101|Das Boot |110|1981-11-11|Dramatic | 02:29
-
-
-
-
-
-
- Compatibility
-
-
-
-
-
- 1998-09-24
-
-
- SQL92
-
- SQL92 defines a different syntax for positioned UPDATE statement:
-
- UPDATE table SET column = expression [, ...]
- WHERE CURRENT OF cursor
-
-
- where cursor
- identifies an open cursor.
-
-
-
-
+
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-09-24
+
+
+ SQL92
+
+ SQL92 defines a different syntax for positioned UPDATE statement:
+
+
+UPDATE table SET column = expression [, ...]
+ WHERE CURRENT OF cursor
+
+
+ where cursor
+ identifies an open cursor.
+
+
+
+
+
+
-
-
-
-VACUUM
-
-SQL - Language Statements
-
-
-
-VACUUM
-
-
-Clean and analyze a
Postgres database
-
-
-
-
-1998-10-04
-
-
-VACUUM [ VERBOSE ] [ ANALYZE ] [ table ]
-VACUUM [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]
-
+
+
+
+ VACUUM
+
+ SQL - Language Statements
+
+
+
+ VACUUM
+
+
+ Clean and analyze a
Postgres database
+
+
+
+
+ 1998-10-04
+
+
+VACUUM [ VERBOSE ] [ ANALYZE ] [ table ]
+VACUUM [ VERBOSE ] ANALYZE [ ER">tBLE> [ (column [, ...] ) ] ]
+
+
+
+
+ 1998-10-04
+
+
+ Inputs
+
+
+
+
+ VERBOSE
+
+ Prints a detailed vacuum activity report for each table.
+
+
+
+
+ ANALYZE
+
+ Updates column statistics used by the optimizer to
+ determine the most efficient way to execute a query.
+ The statistics represent the disbursion of the data in each column.
+ This information is valuable when several execution paths are possible.
+
+
+
+
+ table
+
+ The name of a specific table to vacuum. Defaults to all tables.
+
+
+
+
+ column
+
+ The name of a specific column to analyze. Defaults to all columns.
+
+
+
+
+
+
+
+
+
+ 1998-10-04
+
+
+ Outputs
+
+
+
+
+
+VACUUM
+
+
+ The command has been accepted and the database is being cleaned.
+
+
+
-
-
- 1998-10-04
-
-
- Inputs
-
-
-
-
-
- VERBOSE
-
-
- Prints a detailed vacuum activity report for each table.
-
-
-
-
-
- ANALYZE
-
-
- Updates column statistics used by the optimizer to
- determine the most efficient way to execute a query.
- The statistics represent the disbursion of the data in each column.
- This information is valuable when several execution paths are possible.
-
-
-
-
-
- table
-
-
- The name of a specific table to vacuum. Defaults to all tables.
-
-
-
-
-
- column
-
-
- The name of a specific column to analyze. Defaults to all columns.
-
-
-
-
-
-
+
+
+NOTICE: --Relation table--
+
+
+ The report header for table.
+
+
+
-
-
- 1998-10-04
-
-
- Outputs
-
+
+
+NOTICE: Pages 98: Changed 25, Reapped 74, Empty 0, New 0;
+ Tup 1000: Vac 3000, Crash 0, UnUsed 0, MinLen 188, MaxLen 188;
+ Re-using: Free/Avail. Space 586952/586952; EndEmpty/Avail. Pages 0/74.
+ Elapsed 0/0 sec.
+
+
+ The analysis for table itself.
+
+
+
+
+
+
+NOTICE: Index index: Pages 28;
+ Tuples 1000: Deleted 3000. Elapsed 0/0 sec.
+
+
+ The analysis for an index on the target table.
+
+
+
+
+
+
+
-
-
-
- VACUUM
-
-
- The command has been accepted and the database is being cleaned.
-
-
-
-
-
-
- NOTICE: --Relation table--
-
-
- The report header for table.
-
-
-
+
+
+ 1998-10-04
+
+
+ Description
+
+ VACUUM serves two purposes in
+
Postgres as both a means to reclaim storage and
+ also a means to collect information for the optimizer.
+
-
-
- NOTICE: Pages 98: Changed 25, Reapped 74, Empty 0, New 0;
- Tup 1000: Vac 3000, Crash 0, UnUsed 0, MinLen 188, MaxLen 188;
- Re-using: Free/Avail. Space 586952/586952; EndEmpty/Avail. Pages 0/74.
- Elapsed 0/0 sec.
-
-
- The analysis for table itself.
-
-
-
-
-
-
- NOTICE: Index index: Pages 28;
- Tuples 1000: Deleted 3000. Elapsed 0/0 sec.
-
-
- The analysis for an index on the target table.
-
-
-
-
-
-
-
+ VACUUM opens every class in the database,
+ cleans out records from rolled back transactions, and updates statistics in the
+ system catalogs. The statistics maintained include the number of
+ tuples and number of pages stored in all classes.
+
-
-
- 1998-10-04
-
-
- Description
-
- VACUUM serves two purposes in
-
Postgres as both a means to reclaim storage and
- also a means to collect information for the optimizer.
-
- VACUUM opens every class in the database,
- cleans out records from rolled back transactions, and updates statistics in the
- system catalogs. The statistics maintained include the number of
- tuples and number of pages stored in all classes.
+ Running VACUUM
+ periodically will increase the speed of the database in processing user queries.
+
- Running VACUUM
- periodically will increase the speed of the database in processing user queries.
-
+
+
+ 1998-10-04
+
+
+ Notes
+
+ The open database is the target for VACUUM.
+
+ We recommend that active production databases be cleaned nightly, in order
+ to keep statistics relatively current. The VACUUM
+ query may be executed at any time, however. In particular, after
+ copying a large class into
Postgres
+ or after deleting a large number of
+ records, it may be a good idea to issue a VACUUM
+ query. This will update the system catalogs with the results of all
+ recent changes, and allow the
Postgres
+ query optimizer to make better choices in planning user queries.
+
+ If the server crashes during a VACUUM command,
+ chances are it will leave a lock file hanging around.
+ Attempts to re-run the VACUUM command
+ result in an error message about the creation of a lock file. If you
+ are sure VACUUM is not running,
+ remove the pg_vlock file in your
+ database directory
+ (i.e. PGDATA/base/dbname/pg_vlock).
+
+
+
-
-
- 1998-10-04
-
-
- Notes
-
- The open database is target for VACUUM.
-
- We recommend that active production databases be cleaned nightly, in order
- to keep statistics relatively current. The VACUUM
- query may be executed at any time, however. In particular, after
- copying a large class into
Postgres
- or after deleting a large number of
- records, it may be a good idea to issue a VACUUM
- query. This will update the system catalogs with the results of all
- recent changes, and allow the
Postgres
- query optimizer to make better choices in planning user queries.
-
- If the server crashes during a VACUUM command,
- chances are it will leave a lock file hanging around.
- Attempts to re-run the VACUUM command
- result in an error message about the creation of a lock file. If you
- are sure VACUUM is not running,
- remove the pg_vlock file in your
- database directory
- (i.e. PGDATA/base/dbname/pg_vlock).
-
-
-
-
+
+
+ Usage
+
+ The following is an example from running VACUUM on a table
+ in the regression database:
-
-
- Usage
-
- The following is an example from running VACUUM on a table
- in the regression database:
-
regression=> vacuum verbose analyze onek;
NOTICE: --Relation onek--
NOTICE: Pages 98: Changed 25, Reapped 74, Empty 0, New 0;
NOTICE: Index onek_unique2: Pages 19; Tuples 1000: Deleted 1000. Elapsed 0/0 sec.
NOTICE: Index onek_unique1: Pages 17; Tuples 1000: Deleted 1000. Elapsed 0/0 sec.
VACUUM
-
-
-
+
+
+
+
+
+
+ Compatibility
+
+
+
+ 1998-10-04
+
+
+ SQL92
+
+ There is no VACUUM statement in SQL92.
+
+
+
+
-
-
- Compatibility
-
-
-
- 1998-10-04
-
-
- SQL92
-
- There is no VACUUM statement in SQL92.
-
-
-
-
+