ecpg reference page still needs formatting.
+
+
-
+ id="sql-abort-title">
ABORT
SQL - Language Statements
- 1998-09-27
+ 1999-07-20
-ABORT [ TRANSACTION | WORK ]
+ABORT [ WORK | TRANSACTION ]
+
+
-
+ id="sql-altertable-title">
ALTER TABLE
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
ALTER TABLE table
- [*]
following a name of a table indicates that statement
+ *
following a name of a table indicates that the statement
should be run over that table and all tables below it in the
- inheritance hierarchy.
+ inheritance hierarchy;
+ by default, the attribute will not be added to or renamed in any of the subclasses.
+
+ This should always be done when adding or modifying an attribute in a
+ superclass. If it is not, queries on the inheritance hierarchy
+ such as
+
+SELECT NewColumn FROM SuperClass*
+
+
+ will not work because the subclasses will be missing an attribute
+ found in the superclass.
+
+
+ For efficiency reasons, default values for added attributes are
+ not placed in existing instances of a class.
+ That is, existing instances will have NULL values in the new
+ attributes. If non-NULL values are desired, a subsequent
+ UPDATE query
+ ()
+ should be run.
+
+
+ You must own the class in order to change its schema.
+ Renaming any part of the schema of a system
+ catalog is not permitted.
The PostgreSQL User's Guide has further
information on inheritance.
+
+
-
+ id="sql-alteruser-title">
ALTER USER
SQL - Language Statements
- 1998-09-08
+ 1999-07-20
ALTER USER username [ WITH PASSWORD password ]
ALTER USER is used to change the attributes of a user's
Please note that it is not possible
- to alter a user's "usesysid" via the alter user
+ to alter a user's "usesysid" via the alter user
statement. Also, it is only possible for the
user or any user with read and modify permissions on
If any of the clauses of the alter user statement are
- omitted, the corresponding value in the "pg_shadow" table
+ omitted, the corresponding value in the pg_shadow table
is left unchanged.
Compatibility
-
-
+
+
+
- WORK-TITLE">
+
BEGIN
SQL - Language Statements
- 1999-06-11
+ 1999-07-20
BEGIN [ WORK | TRANSACTION ]
- WORK-1">
+
1999-06-11
Inputs
- None.
+
+
+
+ WORK
+ TRANSACTION
+
+ Optional keywords. They have no effect.
+
+
+
+
- WORK-2">
+
1999-06-11
- WORK-1">
+
1999-06-11
(if execution was successful, otherwise a rollback is done).
BEGIN initiates a user transaction in chained mode,
i.e. all user statements after BEGIN command will
- be executed in a single transaction until an explicit COMMIT, ROLLBACK
+ be executed in a single transaction until an explicit
+ ,
+ ,
or execution abort. Statements in chained mode are executed much faster,
because transaction start/commit requires significant CPU and disk
activity. Execution of multiple statements inside a transaction
is READ COMMITTED, where queries inside the transaction see only changes
committed before query execution. So, you have to use
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
- just after BEGIN if you need more rigorous transaction isolation.
+ just after BEGIN if you need more rigorous transaction isolation.
In SERIALIZABLE mode queries will see only changes committed before
the entire
transaction began (actually, before execution of the first DML statement
(atomic, consistent, isolatable, and durable) property.
- WORK-3">
+
1999-06-11
- Refer to the LOCK statement for further information
+ Refer to
+ for further information
about locking tables inside a transaction.
- WORK-2">
+
Usage
- WORK-3">
+
Compatibility
- BEGIN
- is a
Postgres language extension.
-
-
+
+
1999-06-11
SQL92
- There is no explicit BEGIN WORK command in
SQL92;
+
+ BEGIN
+ is a
Postgres language extension.
+ There is no explicit BEGIN
transaction initiation is always implicit and it terminates either
- with a COMMIT or with a ROLLBACK statement.
+ with a COMMIT or ROLLBACK statement.
+
+
-
+ id="SQL-CLOSE-TITLE">
CLOSE
SQL - Language Statements
- 1998-09-08
+ 1999-07-20
CLOSE cursor
Compatibility
-
+
+
-
+ id="sql-cluster-title">
CLUSTER
SQL - Language Statements
CLUSTER
- Gives storage clustering advice to the backend
+ Gives storage clustering advice to the server
- 1998-09-08
+ 1999-07-20
CLUSTER indexname ON table
-ERROR: relation <tablerelation_number> inherits "invoice"
+ERROR: relation <tablerelation_number> inherits "table"
-ERROR: Relation x does not exist!
+ERROR: Relation table does not exist!
- The relation complained of was not shown in the error message,
+ The specified relation was not shown in the error message,
which contained a random string instead of the relation name.
CLUSTER instructs
Postgres
to cluster the class specified
- by classname approximately
+ by table approximately
based on the index specified by
indexname. The index must
already have been defined on
classname.
+
When a class is clustered, it is physically reordered
based on the index information. The clustering is static.
- Another place CLUSTER is helpful is in cases where you use an
+ Another place where CLUSTER is helpful is in
+ cases where you use an
index to pull out several rows from a table. If you are
requesting a range of indexed values from a table, or a
single indexed value that has multiple rows that match,
Another way to cluster data is to use
+
-SELECT ... INTO TABLE temp FROM ... ORDER BY ...
+SELECT columnlist INTO TABLE newtable
+ FROM table ORDER BY columnlist
- This uses the
Postgres sorting code in
- ORDER BY to match the index, and is much faster for
+
+ which uses the
Postgres sorting code in
+ the ORDER BY clause to match the index, and which is much faster for
unordered data. You then drop the old table, use
ALTER TABLE/RENAME
to rename temp to the old name, and
Compatibility
-
+
+
SQL Commands
&dropType
&dropUser;
&dropView;
+ &end;
&explain;
&fetch;
&grant;
-->
- utilities">
+ applications">
Applications
&createuser;
&destroydb;
&destroyuser;
- &initdb;
- &initlocation;
+ &ecpgRef;
&pgAccess;
&pgAdmin;
&pgDump;
&pgDumpall;
- &postgres;
- &postmaster;
&psqlRef;
&vacuumdb;
+
+
System Applications
+
+ This is reference information for
+ servers and support utilities.
+
+
+
+ &initdb;
+ &initlocation;
+ &ipcclean;
+ &pgPasswd;
+ &pgUpgrade;
+ &postgres;
+ &postmaster;
+
+
+
+
- 1998-09-08
+ 1999-07-20
COMMIT [ WORK | TRANSACTION ]
Inputs
- None.
+
+
+
+ WORK
+ TRANSACTION
+
+ Optional keywords. They have no effect.
+
+
+
+
Compatibility
-
+
+
-
+ id="sql-copy-title">
COPY
SQL - Language Statements
- 1998-09-08
+ 1999-07-20
COPY [ BINARY ] table [ WITH OIDS ]
- FROM { 'filename' |
- stdin }
+ FROM { 'filename' | stdin }
[ USING DELIMITERS 'delimiter' ]
COPY [ BINARY ] table [ WITH OIDS ]
- TO { 'filename' |
- stdout }
+ TO { 'filename' | stdout }
[ USING DELIMITERS 'delimiter' ]
+
table
+
WITH OIDS
+
filename
+
stdin
+
stdout
+
delimiter
-ERROR: error message
+ERROR: reason
COPY moves data between
- standard Unix files.
+ standard file-system files.
COPY instructs
- You must have select access on any table whose values are read by
- COPY, and either insert or update access to a
+ You must have select access on any table
+ whose values are read by
+ COPY, and either
+ insert or update access to a
table into which values are being inserted by COPY.
The backend also needs appropriate Unix permissions for any file read
or written by COPY.
+
+ COPY neither invokes rules nor acts on column defaults.
+ It does invoke triggers, however.
+
+ COPY stops operation at the first error. This
+ should not lead to problems in the event of
+ a COPY FROM, but the
+ target relation will, of course, be partially modified in a
+ COPY TO.
+ VACUUM should be used to clean up
+ after a failed copy.
+
+ Because the Postgres backend's current working directory
+ is not usually the same as the user's
+ working directory, the result of copying to a file
+ "foo" (without
+ additional path information) may yield unexpected results for the
+ naive user. In this case, foo
+ will wind up in $PGDATA/foo. In
+ general, the full pathname as it would appear to the backend server machine
+ should be used when specifying files to
+ be copied.
+
+ Files used as arguments to COPY
+ must reside on or be
+ accessible to the database server machine by being either on
+ local disks or on a networked file system.
+
+ When a TCP/IP connection from one machine to another is used, and a
+ target file is specified, the target file will be written on the
+ machine where the backend is running rather than the user's
+ machine.
+
properly.
+
1998-05-04
-
-
Bugs and features
- COPY neither invokes rules nor acts on column defaults.
- It does invoke triggers, however.
-
- COPY stops operation at the first error. This
- should not lead to problems in the event of
- a COPY FROM, but the
- target relation will, of course, be partially modified in a
-COPY TO.
- The VACUUM query should be used to clean up
- after a failed copy.
-
- Because the Postgres backend's current working directory
- is not usually the same as the user's
- working directory, the result of copying to a file
- "foo" (without
- additional path information) may yield unexpected results for the
- naive user. In this case, foo
- will wind up in $PGDATA/foo. In
- general, the full pathname as it would appear to the backend server machine
-should be used when specifying files to
- be copied.
-
- Files used as arguments to COPY
-must reside on or be
- accessible to the database server machine by being either on
- local disks or on a networked file system.
-
- When a TCP/IP connection from one machine to another is used, and a
- target file is specified, the target file will be written on the
- machine where the backend is running rather than the user's
- machine.
-
-
-
Compatibility
-
+
+
-
+ id="sql-createaggregate-title">
CREATE AGGREGATE
SQL - Language Statements
- 1998-09-09
+ 1999-07-20
-CREATE AGGREGATE name [ AS ]
- ( BASETYPE = data_type
- [ , SFUNC1 = sfunc1
- , STYPE1 = sfunc1_return_type ]
- [ , SFUNC2 = sfunc2
- , STYPE2 = sfunc2_return_type ]
+CREATE AGGREGATE name [ AS ] ( BASETYPE = data_type
+ [ , SFUNC1 = sfunc1, STYPE1 = sfunc1_return_type ]
+ [ , SFUNC2 = sfunc2, STYPE2 = sfunc2_return_type ]
[ , FINALFUNC = ffunc ]
[ , INITCOND1 = initial_condition1 ]
- [ , INITCOND2 = initial_condition2 ]
- )
+ [ , INITCOND2 = initial_condition2 ] )
Refer to the chapter on aggregate functions
- in the PostgreSQL Programmer's Guide
- on aggregate functions for
+ in the PostgreSQL Programmer's Guide for
complete examples of usage.
-
+
+
+
-
+ id="sql-createdatabase-title">
CREATE DATABASE
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
CREATE DATABASE name [ WITH LOCATION = 'dbpath' ]
dbpath
- An alternate location can be specified as either an
- environment variable known to the backend server
- (e.g. 'PGDATA2') or as an absolute path name
- (e.g. '/usr/local/pgsql/data').
- In either case, the location must be pre-configured
- by initlocation.
+ An alternate location for the new database. See below for caveats.
The creator becomes the administrator of the new database.
+ An alternate location can be specified as either an
+ environment variable known to the backend server
+ (e.g. 'PGDATA2') or, if the server is built to
+ allow it, as an absolute path name
+ (e.g. '/usr/local/pgsql/data').
+ In either case, the location must be pre-configured
+ by initlocation.
+
+
1998-04-15
Use DROP DATABASE to remove a database.
+
+ There are security and data integrity issues
+ involved with using alternate database locations
+ specified with absolute path names, and by default
+ only an environment variable known to the backend may be
+ specified for an alternate location.
+ See the Administrator's Guide for more information.
+
+
+
-
-
- Bugs
-
- There are security and data integrity issues
- involved with using alternate database locations
- specified with absolute path names, and by default
- only an environment variable known to the backend may be
- specified for an alternate location.
- See the Administrator's Guide for more information.
-
-
-
-
-
Compatibility
There is no CREATE DATABASE statement in SQL92.
-
The equivalent command in standard SQL is CREATE SCHEMA.
+
+
-
+ id="sql-createfunction-title">
CREATE FUNCTION
SQL - Language Statements
- 1998-09-09
+ 1999-07-20
CREATE FUNCTION name ( [ ftype [, ...] ] )
The data type of function arguments.
+ The input types may be base or complex types, or
+ opaque.
+ opaque indicates that the function
+ accepts arguments of an invalid type such as char *.
The return data type.
+ The output type may be specified as a base type, complex type,
+ setof type,
+ or opaque.
+ The setof
+ modifier indicates that the function will return a set of items,
+ rather than a single item.
or 'plname',
where 'plname'
is the name of a created procedural
- language. See CREATE LANGUAGE for details.
+ language. See
+
+ for details.
Notes
- Refer to the chapter on functions
-in the PostgreSQL Programmer's Guide
- for further information.
+ Refer to the chapter in
+ the PostgreSQL Programmer's Guide
+ on extending
+ for further information on writing external functions.
+
Use DROP FUNCTION
to drop user-defined functions.
-
Postgres allows function "overloading";
- that is, the same name can be used for several different functions
- so long as they have distinct argument types. This facility must be
- used with caution for INTERNAL and C-language functions, however.
-
+
Postgres allows function "overloading";
+ that is, the same name can be used for several different functions
+ so long as they have distinct argument types. This facility must be
+ used with caution for internal
+ and C-language functions, however.
+
- Two INTERNAL functions cannot have the same C name without causing
- errors at link time. To get around that, give them different C names
- (for example, use the argument types as part of the C names), then
- specify those names in the AS clause of CREATE FUNCTION.
- If the AS clause is left empty then CREATE FUNCTION
- assumes the C name of the function is the same as the SQL name.
-
+ Two internal
+ functions cannot have the same C name without causing
+ errors at link time. To get around that, give them different C names
+ (for example, use the argument types as part of the C names), then
+ specify those names in the AS clause of CREATE FUNCTION.
+ If the AS clause is left empty then CREATE FUNCTION
+ assumes the C name of the function is the same as the SQL name.
+
- For dynamically-loaded C functions, the SQL name of the function must
- be the same as the C function name, because the AS clause is used to
- give the path name of the object file containing the C code. In this
- situation it is best not to try to overload SQL function names. It
- might work to load a C function that has the same C name as an internal
- function or another dynamically-loaded function --- or it might not.
- On some platforms the dynamic loader may botch the load in interesting
- ways if there is a conflict of C function names. So, even if it works
- for you today, you might regret overloading names later when you try
- to run the code somewhere else.
-
+ For dynamically-loaded C functions, the SQL name of the function must
+ be the same as the C function name, because the AS clause is used to
+ give the path name of the object file containing the C code. In this
+ situation it is best not to try to overload SQL function names. It
+ might work to load a C function that has the same C name as an internal
+ function or another dynamically-loaded function --- or it might not.
+ On some platforms the dynamic loader may botch the load in interesting
+ ways if there is a conflict of C function names. So, even if it works
+ for you today, you might regret overloading names later when you try
+ to run the code somewhere else.
+
+
+ A C function cannot return a set of values.
+
- To create a C function, calling a routine from a user-created
+ This example creates a C function by calling a routine from a user-created
shared library. This particular routine calculates a check
digit and returns TRUE if the check digit in the function parameters
is correct. It is intended for use in a CHECK contraint.
-
-
- Bugs
-
- A C function cannot return a set of values.
-
-
-
Compatibility
- CREATE FUNCTION is
- a
Postgres language extension.
-
+
+ 1998-04-15
+
+
+ SQL92
+
+
+ CREATE FUNCTION is
+ a
Postgres language extension.
+
+
+
+
1998-09-09
+
+
-
+ id="sql-createindex-title">
CREATE INDEX
SQL - Language Statements
- 1998-09-09
+ 1999-07-20
-CREATE [ UNIQUE ] INDEX index_name
- ON table [ USING acc_name ]
- ( column [ ops_name] [, ...] )
-CREATE [ UNIQUE ] INDEX index_name
- ON table [ USING acc_name ]
- ( func_name( r">colle> [, ... ]) ops_name )
+CREATE [ UNIQUE ] INDEX index_name ON table
+ [ USING acc_name ] ( column [ ops_name] [, ...] )
+CREATE [ UNIQUE ] INDEX index_name ON table
+ [ USING acc_name ] ( func_name( r">colle> [, ... ]) ops_name )
+
index_name
+
table
+
acc_name
the name of the access method which is to be used for
the index. The default access method is BTREE.
Postgres provides three access methods for secondary indexes:
+
BTREE
+
RTREE
+
HASH
-
+
ops_name
- An associated operator class.
- The following select list returns all ops_names:
-
-SELECT am.amname AS acc_name,
- opc.opcname AS ops_name,
- opr.oprname AS ops_comp
- FROM pg_am am, pg_amop amop,
- pg_opclass opc, pg_operator opr
- WHERE amop.amopid = am.oid AND
- amop.amopclaid = opc.oid AND
- amop.amopopr = opr.oid
- ORDER BY acc_name, ops_name, ops_comp
-
+ An associated operator class. See below for details.
+
func_name
CREATE INDEX constructs an index
- index_name.
- on the specified
- table.
+ index_name
+ on the specified table.
+
In the first syntax shown above, the key fields for the
index are specified as column names; a column may also have
operator class is the appropriate operator class for that
field type.
+
- In the second syntax, an index is defined
+ In the second syntax shown above, an index is defined
on the result of a user-defined function
func_name applied
- to one or more attributes of a single class. These functional
- indexes can be used to obtain fast access to data
+ to one or more attributes of a single class.
+ These functional indices
+ can be used to obtain fast access to data
based on operators that would normally require some
transformation to apply them to the base data.
+ Postgres provides btree, rtree and hash access methods for
+ secondary indices. The btree access method is an implementation of
+ the Lehman-Yao high-concurrency btrees. The rtree access method
+ implements standard rtrees using Guttman's quadratic split algorithm.
+ The hash access method is an implementation of Litwin's linear
+ hashing. We mention the algorithms used solely to indicate that all
+ of these access methods are fully dynamic and do not have to be
+ optimized periodically (as is the case with, for example, static hash
+ access methods).
+
+
1998-09-09
Notes
+
+ The Postgres query optimizer will consider using btree indices in a scan
+ whenever an indexed attribute is involved in a comparison using one of:
+
+
+ <
+ <=
+ =
+ >=
+ >
+
+
+
+ Both box classes support indices on the box data
+ The difference between them is that bigbox_ops
+ scales box coordinates down, to avoid floating point exceptions from
+ doing multiplication, addition, and subtraction on very large
+ floating-point coordinates. If the field on which your rectangles lie
+ is about 20,000 units square or larger, you should use
+ bigbox_ops.
+ The poly_ops operator class supports rtree
+ indices on polygon data.
+
+
+ query optimizer will consider using an rtree index whenever
+ an indexed attribute is involved in a comparison using one of:
+
+
+ <<
+ &<
+ &>
+ >>
+ @
+ ~=
+ &&
+
+
+
+ query optimizer will consider using a hash index whenever
+ an indexed attribute is involved in a comparison using
+ the = operator.
+
+
Currently, only the BTREE access method supports multi-column
indexes. Up to 7 keys may be specified.
+
- Use <command>DROP INDEX>
+ Use <xref linkend="sql-dropindex-title" endterm="sql-dropindex-title">
to remove an index.
+
+ The int24_ops
+ operator class is useful for constructing indices on int2 data, and
+ doing comparisons against int4 data in query qualifications.
+ Similarly, int42_ops
+ support indices on int4 data that is to be compared against int2 data
+ in queries.
+
+
+ The following select list returns all ops_names:
+
+SELECT am.amname AS acc_name,
+ opc.opcname AS ops_name,
+ opr.oprname AS ops_comp
+ FROM pg_am am, pg_amop amop,
+ pg_opclass opc, pg_operator opr
+ WHERE amop.amopid = am.oid AND
+ amop.amopclaid = opc.oid AND
+ amop.amopopr = opr.oid
+ ORDER BY acc_name, ops_name, ops_comp
+
+
Compatibility
-
+
+
-
+ id="sql-createlanguage-title">
CREATE LANGUAGE
SQL - Language Statements
- 1998-09-09
+ 1999-07-20
CREATE [ TRUSTED ] PROCEDURAL LANGUAGE 'langname'
-
+
+
HANDLER call_handler
+
comment
sql |postgres
+
+ Since the call handler for a procedural language must be
+ registered with
Postgres in the 'C' language,
+ it inherits
+ all the capabilities and restrictions of 'C' functions.
+
+
+ At present, the definitions for a procedural language cannot be
+ changed once they have been created.
-
-
- Restrictions
-
- Since the call handler for a procedural language must be
- registered with
Postgres in the 'C' language,
- it inherits
- all the capabilities and restrictions of 'C' functions.
-
-
-
-
- Bugs
-
- At present, the definitions for a procedural language cannot be
- changed once they have been created.
-
-
-
Usage
Compatibility
- CREATE LANGUAGE is a
Postgres extension.
-
SQL92
+
+ CREATE LANGUAGE
+ is a
Postgres extension.
There is no CREATE LANGUAGE statement in
+
+
-
+ id="sql-createoperator-title">
CREATE OPERATOR
SQL - Language Statements
- 1999-04-14
+ 1999-07-20
-CREATE OPERATOR name (
- PROCEDURE = func_name
- [, LEFTARG = type1 ]
- [, RIGHTARG = type2 ]
- [, COMMUTATOR = com_op ]
- [, NEGATOR = neg_op ]
- [, RESTRICT = res_proc ]
- [, JOIN = join_proc ]
- [, HASHES ]
- [, SORT1 = left_sort_op ]
- [, SORT2 = right_sort_op ]
- )
+CREATE OPERATOR name ( PROCEDURE = func_name
+ [, LEFTARG = type1 ] [, RIGHTARG = type2 ]
+ [, COMMUTATOR = com_op ] [, NEGATOR = neg_op ]
+ [, RESTRICT = res_proc ] [, JOIN = join_proc ]
+ [, HASHES ] [, SORT1 = left_sort_op ] [, SORT2 = right_sort_op ] )
Compatibility
- CREATE OPERATOR is a
Postgres extension.
-
SQL92
+
- There is no CREATE OPERATOR statement in
SQL92.
+ CREATE OPERATOR
+ is a
Postgres extension.
+ There is no CREATE OPERATOR
+
+
-
+ id="sql-createrule-title">
CREATE RULE
SQL - Language Statements
- 1998-09-11
+ 1999-07-20
CREATE RULE name AS ON event
Description
+
+ rule system allows one to define an
+ alternate action to be performed on updates, inserts, or deletions
+ from database tables or classes. Currently, rules are used to
+ implement table views.
+
+
The semantics of a rule is that at the time an individual instance is
accessed, updated, inserted or deleted, there is a current instance (for
current.attribute-name
and new.attribute-name.
+
The action part of the rule
executes with the same command and transaction identifier as the user
SELECT * FROM emp;
-
+
You must have rule definition access to a class in order
to define a rule on it. Use GRANT
and REVOKE to change permissions.
+
+ The object in a
SQL rule cannot be an array reference and
+ cannot have parameters.
+
+
+ Aside from the "oid" field, system attributes cannot be
+ referenced anywhere in a rule. Among other things, this
+ means that functions of instances (e.g., foo(emp) where
+ emp is a class) cannot be called anywhere in a rule.
+
+
+ The rule system stores the rule text and query plans as
+ text attributes. This implies that creation of rules may
+ fail if the rule plus its various internal representations
+ exceed some value that is on the order of one page (8KB).
+
-
-
- Bugs
-
- The object in a
SQL rule cannot be an array reference and
- cannot have parameters.
-
- Aside from the "oid" field, system attributes cannot be
- referenced anywhere in a rule. Among other things, this
- means that functions of instances (e.g., "foo(emp)" where
- "emp" is a class) cannot be called anywhere in a rule.
-
- The rule system stores the rule text and query plans as
- text attributes. This implies that creation of rules may
- fail if the rule plus its various internal representations
- exceed some value that is on the order of one page (8KB).
-
-
-
Compatibility
-
CREATE RULE statement is a
Postgres
- language extension.
-
SQL92
+
+
CREATE RULE statement is a
Postgres
+ language extension.
There is no
CREATE RULE statement in
SQL92.
+
+
-
+ id="sql-createsequence-title">
CREATE SEQUENCE
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
-CREATE SEQUENCE seqname
- [ INCREMENT increment ]
- [ MINVALUE minvalue ]
- [ MAXVALUE maxvalue ]
- [ START start ]
- [ CACHE cache ]
- [ CYCLE ]
+CREATE SEQUENCE seqname [ INCREMENT increment ]
+ [ MINVALUE minvalue ] [ MAXVALUE maxvalue ]
+ [ START start ] [ CACHE cache ] [ CYCLE ]
+
increment
+
minvalue
+
maxvalue
+
start
+
cache
+
CYCLE
table with the name seqname.
The generator will be "owned" by the user issuing the command.
+
After a sequence is created, you may use the function
nextval(seqname)
Use a query like
+
SELECT * FROM sequence_name;
+
to get the parameters of a sequence.
+
Aside from fetching the original
parameters, you can use
+
SELECT last_value FROM sequence_name;
+
to obtain the last value allocated by any backend.
parameters, you can use
+
Low-level locking is used to enable multiple simultaneous
calls to a generator.
Compatibility
-
CREATE SEQUENCE is a
Postgres
- language extension.
-
SQL92
+
+
CREATE SEQUENCE is a
Postgres
+ language extension.
There is no CREATE SEQUENCE statement
+
+
-
+ id="sql-createtable-title">
CREATE TABLE
SQL - Language Statements
- 1998-09-11
+ 1999-07-20
CREATE [ TEMPORARY | TEMP ] TABLE table (
table
- The name of a new table to be created.
+ The name of a new class or table to be created.
Description
+
- CREATE TABLE will enter a new table into the current data
- base. The table will be "owned" by the user issuing the
+ CREATE TABLE will enter a new class or table
+ into the current data base. The table will be "owned" by the user issuing the
command.
+
+ Each type
+ may be a simple type, a complex type (set) or an array type.
+ Each attribute may be specified to be non-null and
+ each may have a default value, specified by the
+ .
+
+
+
+ As of Postgres version 6.0, consistant array dimensions within an
+ attribute are not enforced. This will likely change in a future
+ release.
+
+
+
+
+ The optional INHERITS
+ clause specifies a collection of class names from which this class
+ automatically inherits all fields. If any inherited field name
+ appears more than once, Postgres reports an error. Postgres automatically
+ allows the created class to inherit functions on classes above it in
+ the inheritance hierarchy. Inheritance of functions is done according
+ to the conventions of the Common Lisp Object System (CLOS).
+
+
+ Each new table or class table
+ is automatically created as a type. Therefore, one or more instances
+ from the class are automatically a type and can be used in
+
+ or other CREATE TABLE statements.
+
+
The new table is created as a heap with no initial data.
A table can have no more than 1600 columns (realistically,
1998-09-11
-
+
id="R1-SQL-DEFAULTCLAUSE-1-TITLE">
DEFAULT Clause
1998-09-11
-
+
id="R1-SQL-COLUMNCONSTRAINT-1-TITLE">
Column CONSTRAINT Clause
Inputs
+
name
Description
+
+ The optional constraint
+ clauses specify constraints or tests which new or updated entries
+ must satisfy for an insert or update operation to succeed. Each constraint
+ must evaluate to a boolean expression. Multiple attributes may be referenced within
+ a single constraint. The use of PRIMARY KEY
+ as a table constraint
+ is mutually incompatible with PRIMARY KEY as a column constraint.
+
+
- A Constraint is a named rule: an SQL object which helps define
+ A constraint is a named rule: an SQL object which helps define
valid sets of values by putting limits on the results of INSERT,
UPDATE or DELETE operations performed on a Base Table.
+
There are two ways to define integrity constraints:
table constraints, covered later, and column constraints, covered here.
+
A column constraint is an integrity constraint defined as part
of a column definition, and logically becomes a table
constraint as soon as it is created. The column
constraints available are:
+
PRIMARY KEY
REFERENCES
-
+
+
+
-
+ id="SQL-CREATETABLEAS-TITLE">
CREATE TABLE AS
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
CREATE TABLE table [ (column [, ...] ) ]
Description
- CREATE TABLE AS enables a table to be created from the contents of
- an existing table. It has functionality equivalent to SELECT TABLE INTO,
+ CREATE TABLE AS enables a table to be created
+ from the contents of an existing table.
+ It is functionality equivalent to
+ ,
but with perhaps a more direct syntax.
+
+
-
+ id="SQL-CREATETRIGGER-TITLE">
CREATE TRIGGER
SQL - Language Statements
- 1998-09-21
+ 1999-07-20
CREATE TRIGGER name { BEFORE | AFTER } { event [OR ...] }
Description
+
CREATE TRIGGER will enter a new trigger into the current
data base. The trigger will be associated with the relation
relname and will execute
the specified function funcname.
+
- The trigger can be specified to fire either before the
+ The trigger can be specified to fire either before BEFORE the
operation is attempted on a tuple (before constraints
- are checked and the INSERT, UPDATE or DELETE is attempted) or
- after the operation has been attempted (e.g. after constraints
- are checked and the INSERT, UPDATE or DELETE has completed). If the
+ are checked and the INSERT, UPDATE or
+ DELETE is attempted) or
+ AFTER the operation has been attempted (e.g. after constraints
+ are checked and the INSERT,
+ UPDATE or DELETE has
+ completed). If the
trigger fires before the event, the trigger may
skip the operation for the current tuple, or change the tuple
- being inserted (for INSERT and UPDATE operations only). If
+ being inserted (for INSERT and
+ UPDATE operations only). If
the trigger fires after the event, all changes, including the
last insertion, update, or deletion, are "visible" to the trigger.
+
Refer to the chapters on SPI and Triggers in the
-PostgreSQL Programmer's Guide for more
+ PostgreSQL Programmer's Guide for more
information.
+
1998-09-21
CREATE TRIGGER is a
Postgres
- language extension.
+ language extension.
Only the relation owner may create a trigger on this relation.
Compatibility
-
SQL92
+
There is no
CREATE TRIGGER in
SQL92.
- However, foreign keys are not yet implemented (as of version 6.4) in
+ However, foreign keys are not yet implemented (as of version 6.5) in
+
+
- 1998-09-21
+ 1999-07-20
-CREATE TYPE typename (
- INPUT = input_function
- , OUTPUT = output_function
- , INTERNALLENGTH = (internallength | VARIABLE)
- [ , EXTERNALLENGTH = (externallength | VARIABLE) ]
- [ , ELEMENT = element ]
- [ , DELIMITER = delimiter ]
- [ , DEFAULT = "default" ]
- [ , SEND = send_function ]
- [ , RECEIVE = receive_function ]
- [ , PASSEDBYVALUE ]
-)
+CREATE TYPE typename ( INPUT = input_function, OUTPUT = output_function
+ , INTERNALLENGTH = { internallength | VARIABLE } [ , EXTERNALLENGTH = { externallength | VARIABLE } ]
+ [ , DEFAULT = "default" ]
+ [ , ELEMENT = element ] [ , DELIMITER = delimiter ]
+ [ , SEND = send_function ] [ , RECEIVE = receive_function ]
+ [ , PASSEDBYVALUE ] )
+
- INTERNALLENGTH internallength
+ internallength
A literal value, which specifies the internal length of
+
- EXTERNALLENGTH externallength
+ externallength
A literal value, which specifies the external length of
+
- INPUT input_function
+ input_function
- The name of a function, created by CREATE FUNCTION, which
+ The name of a function, created by
+ CREATE FUNCTION, which
converts data from its external form to the type's
internal form.
+
- OUTPUT output_function
+ output_function
The name of a function, created by CREATE FUNCTION, which
+
element
+
delimiter
+
default
send_function
- The name of a function, created by CREATE FUNCTION, which
+ The name of a function, created by CREATE FUNCTION, which
converts data of this type into a form suitable for
transmission to another machine.
- Is this right?
receive_function
- The name of a function, created by CREATE FUNCTION, which
+ The name of a function, created by CREATE FUNCTION, which
converts data of this type from a form suitable for
transmission from another machine to internal form.
- Is this right?
Description
+
CREATE TYPE allows the user to register a new user data
type with Postgres for use in the current data base. The
the name of the new type and must be unique within the
types defined for this database.
+
CREATE TYPE requires the registration of two functions
(using create function) before defining the type. The
the input and output functions must be declared to take
one or two arguments of type "opaque".
+
New base data types can be fixed length, in which case
internallength is a
externallength
keyword.
+
To indicate that a type is an array and to indicate that a
type has array elements, indicate the type of the array
an array of 4 byte integers ("int4"), specify
+
To indicate the delimiter to be used on arrays of this
type, delimiter
set to a specific character. The default delimiter is the comma
(",").
+
A default value is optionally available in case a user
wants some specific bit pattern to mean "data not present."
How does the user specify that bit pattern and associate
it with the fact that the data is not present>
+
- The optional functions
+ The optional arguments
send_function and
receive_function
are used when the application program requesting Postgres
characters do not have to be converted if passed from
a Sun-4 to a DECstation, but many other types do.
+
The optional flag, , indicates that operators
and functions which use this data type should be passed an
may not pass by value types whose internal representation is
more than four bytes.
+
For new base types, a user can define operators, functions
and aggregates using the appropriate facilities described
This command creates the box data type and then uses the
type in a class definition:
-
CREATE TYPE box (INTERNALLENGTH = 8,
INPUT = my_procedure_1, OUTPUT = my_procedure_2);
CREATE TABLE myboxes (id INT4, description box);
-
+
+
+
This command creates a variable length array type with
- integer elements.
+ integer elements:
CREATE TYPE int4array (INPUT = array_in, OUTPUT = array_out,
CREATE TABLE myarrays (id int4, numbers int4array);
+
This command creates a large object type and uses it in
a class definition:
-
-
Restrictions
+
+
+ 1998-09-21
+
+
+ Notes
+
+
Type names cannot begin with the underscore character
("_") and can only be 31 characters long. This is because
with a name consisting of the base type's name prepended
with an underscore.
-
-
-
- 1998-09-21
-
-
- Notes
-
Refer to DROP TYPE to remove an existing type.
+
+
- 1998-09-21
+ 1999-07-20
CREATE USER username
[ WITH PASSWORD password ]
- [ CREATEDB | NOCREATEDB ]
- [ CREATEUSER | NOCREATEUSER ]
+ [ CREATEDB | NOCREATEDB ] [ CREATEUSER | NOCREATEUSER ]
[ IN GROUP groupname [, ...] ]
[ VALID UNTIL 'abstime' ]
Inputs
+
username
CREATE USER will add a new user to an instance of
+
The new user will be given a usesysid of:
Compatibility
-
SQL92
+
There is no CREATE USER statement in SQL92.
+
+
-
+ id="SQL-CREATEVIEW-TITLE">
CREATE VIEW
SQL - Language Statements
- 1998-09-21
+ 1999-07-20
-CREATE VIEW view
- AS SELECT query
+CREATE VIEW view AS SELECT query
Inputs
+
view
Description
- CREATE VIEW will define a view of a table. This view is
- not physically materialized. Specifically, a query
- rewrite retrieve rule is automatically generated
- to support retrieve operations on views.
+ CREATE VIEW will define a view of a table or
+ class. This view is not physically materialized. Specifically, a query
+ rewrite retrieve rule is automatically generated to support
+ retrieve operations on views.
Notes
+
- Use the DROP VIEW statement to drop views.
+ Currently, views are read only.
-
-
-
- 1998-09-21
-
-
- Bugs
-
- Currently, views are read only.
+ Use the DROP VIEW statement to drop views.
Compatibility
-
+
LOCAL
+
CASCADE
+
+
-
+ id="APP-CREATEDB-TITLE">
Application
- 1998-10-02
+ 1999-07-20
createdb [ dbname ]
PGREALM
environment variables will be passed on to
- and processed as described in
- linkend="app-psql">.
+ and processed as described in .
+
+
-
+ id="APP-CREATEUSER-TITLE">
Application
- 1998-10-02
+ 1999-07-20
createuser [ username ]
PGREALM
environment variables will be passed on to
- and processed as described in .
+ and processed as described in
+ .
+
+
-
+ id="SQL-DECLARE-TITLE">
DECLARE
SQL - Language Statements
- 1998-09-04
+ 1999-07-20
DECLARE cursor [ BINARY ] [ INSENSITIVE ] [ SCROLL ]
Description
- DECLARE allows a user to create cursors, which can be used to retrieve
- a small number of rows at a time out of a larger query. Cursors can return
- data either in text or in binary foramt.
+ DECLARE allows a user to create cursors, which
+ can be used to retrieve
+ a small number of rows at a time out of a larger query. Cursors can
+ return data either in text or in binary format using
+ .
- Normal cursors return data in text format, either ASCII or another
+ Normal cursors return data in text format, either ASCII or another
encoding scheme depending on how the
Postgres
backend was built. Since
data is stored natively in binary format, the system must
do a conversion to produce the text format. In addition,
text formats are often larger in size than the corresponding binary format.
Once the information comes back in text form, the client
- application may have to convert it to a binary format to
- manipulate it anyway.
-
-
+ application may need to convert it to a binary format to
+ manipulate it.
BINARY cursors give you back the data in the native binary
- representation. So binary cursors will tend to be a
- little faster since they suffer less conversion overhead.
+ representation.
you would get a string of '1' with a default cursor
whereas with a binary cursor you would get
a 4-byte value equal to control-A ('^A').
+
-
- BINARY cursors should be used carefully. User applications such
- as
psql are not aware of binary cursors
- and expect data to come back in a text format.
-
-
+ BINARY cursors should be used carefully. User applications such
+ as
psql are not aware of binary cursors
+ and expect data to come back in a text format.
- However, string representation is architecture-neutral whereas binary
- representation can differ between different machine architectures.
+ String representation is architecture-neutral whereas binary
+ representation can differ between different machine architectures
+ and
Postgres does not resolve
+ byte ordering or representation issues for binary cursors.
Therefore, if your client machine and server machine use different
representations (e.g. "big-endian" versus "little-endian"),
you will probably not want your data returned in
binary format.
+ However, binary cursors may be a
+ little more efficient since there is less conversion overhead in
+ the server to client data transfer.
Notes
+
- Cursors are only available in transactions.
+ Cursors are only available in transactions. Use to
+ ,
+
+ and
+
+ to define a transaction block.
+
- does not have an explicit OPEN cursor
+ In
SQL92 cursors are only available in
+ embedded
SQL (
ESQL) applications.
+ does not implement an explicit OPEN cursor
statement; a cursor is considered to be open when it is declared.
-
-
- In
SQL92 cursors are only available in
- embedded applications.
ecpg, the
- embedded SQL preprocessor for
Postgres,
- supports the
SQL92 conventions, including those
- involving DECLARE and OPEN statements.
-
-
+ embedded SQL preprocessor for
Postgres,
+ supports the
SQL92 cursor conventions, including those
+ involving DECLARE and OPEN statements.
Compatibility
-
+
+
-
+ id="SQL-DELETE-TITLE">
DELETE
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
DELETE FROM table [ WHERE condition ]
Description
+
DELETE removes rows which satisfy the WHERE
clause from the specified table.
+
If the condition (WHERE clause) is absent,
the effect is to delete all rows in the table.
The result is a valid, but empty table.
+
You must have write access to the table in order to modify
it, as well as read access to any table whose values are
DELETE FROM films WHERE kind <> 'Musical';
SELECT * FROM films;
+
code |title |did| date_prod|kind |len
-----+-------------------------+---+----------+----------+------
UA501|West Side Story |105|1961-01-03|Musical | 02:32
TC901|The King and I |109|1956-08-11|Musical | 02:13
WD101|Bed Knobs and Broomsticks|111| |Musical | 01:57
(3 rows)
+
DELETE FROM films;
SELECT * FROM films;
+
code|title|did|date_prod|kind|len
----+-----+---+---------+----+---
(0 rows)
+
Compatibility
-
+
+
-
+ id="APP-DESTROYDB-TITLE">
Application
- 1998-10-02
+ 1999-07-20
destroydb [ dbname ]
PGREALM
environment variables will be passed on to
- and processed as described in
- linkend="app-psql">.
+ and processed as described in .
+
+
-
+ id="APP-DESTROYUSER-TITLE">
Application
- 1998-10-02
+ 1999-07-20
destroyuser [ username ]
PGREALM
environment variables will be passed on to
- and processed as described in
- linkend="app-psql">.
+ and processed as described in .
+
Once invoked,
destroyuser
will warn you about the databases that will be destroyed in the
+
+
-
+ id="SQL-DROPAGGREGATE-TITLE">
DROP AGGREGATE
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
DROP AGGREGATE name type
Notes
+
- The DROP AGGREGATE statement is a
- language extension.
-
- Refer to the CREATE AGGREGATE statement to
- create aggregate functions.
+ Use
+
+ to create aggregate functions.
Compatibility
-
SQL92
+
- There is no DROP AGGREGATE statement in
SQL92.
+ There is no DROP AGGREGATE statement
+ in
SQL92; the statement is a
+ language extension.
+
+
-
+ id="SQL-DROPDATABASE-TITLE">
DROP DATABASE
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
DROP DATABASE name
-
DROP DATABASE statement is a
Postgres
- language extension.
-
-
- This query cannot be executed while connected to the target
- database. It is usually preferable to use the
- destroydb script instead.
-
-
+ This query cannot be executed while connected to the target
+ database. It is usually preferable to use
+
+ instead.
- Refer to the CREATE DATABASE statement for
- information on how to create a database.
+ Refer to
+ and
+
+ for information on how to create a database.
Compatibility
-
SQL92
+
- There is no
DROP DATABASE in
SQL92.
+ DROP DATABASE statement is a
+
Postgres language extension;
+ there is no such command in
SQL92.
+
+
-
+ id="SQL-DROPFUNCTION-TITLE">
DROP FUNCTION
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
DROP FUNCTION name ( [ type [, ...] ] )
Notes
+
+ Refer to
+
+ for information on creating aggregate functions.
+
+
- Refer to CREATE FUNCTION
- to create aggregate functions.
+ No checks are made to ensure that types, operators or access
+ methods that rely on the function have been removed first.
Usage
+
This command removes the square root function:
-
-
- Bugs
-
- No checks are made to ensure that types, operators or access
- methods that rely on the function have been removed first.
-
-
-
Compatibility
- DROP FUNCTION is a
Postgres language extension.
-
+
+ 1999-07-20
+
+
+ SQL92
+
+
+ DROP FUNCTION
+ is a
Postgres language extension.
+
+
+
+
1998-04-15
SQL/PSM is a proposed standard to enable function extensibility.
The SQL/PSM DROP FUNCTION statement has the following syntax:
+
+
DROP [ SPECIFIC ] FUNCTION name { RESTRICT | CASCADE }
- programlisting>
+ synopsis>
+
+
-
+ id="SQL-DROPINDEX-TITLE">
DROP INDEX
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
DROP INDEX index_name
language extension.
- Refer to the CREATE INDEX statement for
- information on how to create indexes.
+ Refer to
+
+ for information on how to create indexes.
Compatibility
-
+
+
-
+ id="SQL-DROPLANGUAGE-TITLE">
DROP LANGUAGE
SQL - Language Statements
- 1998-04-15
+ 1999-07-20
DROP PROCEDURAL LANGUAGE 'name'
a
Postgres language extension.
- Refer to CREATE PROCEDURAL LANGUAGE
+ Refer to
+
for information on how to create procedural languages.
-
-
-
-
- 1998-04-15
-
-
- Bugs
-
+
No checks are made if functions or trigger procedures registered
in this language still exist. To re-enable them without having
Compatibility
-
+
+
-
+ id="SQL-DROPOPERATOR-TITLE">
DROP OPERATOR
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
DROP OPERATOR id ( type | NONE [,...] )
language extension.
- Refer to CREATE OPERATOR for
- information on how to create operators.
+ Refer to
+
+ for information on how to create operators.
It is the user's responsibility to remove any access methods and
Compatibility
-
+
+
-
+ id="SQL-DROPRULE-TITLE">
DROP RULE
SQL - Language Statements
language extension.
+
Refer to CREATE RULE for
information on how to create rules.
-
-
-
- 1998-09-22
-
-
- Bugs
-
Once a rule is dropped, access to historical information
the rule has written may disappear.
Compatibility
-
-
+
1998-09-22
+
+
-
+ id="SQL-DROPSEQUENCE-TITLE">
DROP SEQUENCE
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
DROP SEQUENCE name [, ...]
Compatibility
-
+
+
-
+ id="SQL-DROPTABLE-TITLE">
DROP TABLE
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
DROP TABLE name [, ...]
Compatibility
-
+
+
-
+ id="SQL-DROPTRIGGER-TITLE">
DROP TRIGGER
SQL - Language Statements
Compatibility
-
+
+
-
+ id="SQL-DROPTYPE-TITLE">
DROP TYPE
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
DROP TYPE typename
functions, aggregates, access methods, subtypes, and classes
that use a deleted type.
-
-
-
- 1998-09-22
-
-
- Bugs
-
If a built-in type is removed, the behavior of the backend
is unpredictable.
Compatibility
-
SQL3
-
DROP TYPE is a
SQL3 statement.
+
DROP TYPE is a
SQL3 statement.
+
+
-
+ id="SQL-DROPUSER-TITLE">
DROP USER
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
DROP USER name
Compatibility
-
+
+
-
+ id="SQL-DROPVIEW-TITLE">
DROP VIEW
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
DROP VIEW name
Compatibility
-
--- /dev/null
+
+
+
+
+
+
+ Application
+
+
+
+
+
+ Embedded SQL C preprocessor
+
+
+
+
+ 1999-07-20
+
+
+ecpg [ -v ] [ -t ] [ -I include-path ] [ -o outfile ] file1 [ file2 ] [ ... ]
+
+
+
+
+ 1999-07-20
+
+
+ Inputs
+
+
ecpg accepts the following command
+ line arguments:
+
+
+
+ file
+
+
+
+
+
+
+
+
+
+
+ 1998-11-05
+
+
+ Outputs
+
+
ecpg will create a file or
+ write to stdout.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-11-05
+
+
+ Description
+
+
+
+
+
+
+
+
--- /dev/null
+
+
+
+
+
+ END
+
+ SQL - Language Statements
+
+
+
+ END
+
+
+ Commits the current transaction
+
+
+
+
+
+ 1999-07-20
+
+
+END [ WORK | TRANSACTION ]
+
+
+
+
+ 1998-09-08
+
+
+ Inputs
+
+
+
+
+ WORK
+ TRANSACTION
+
+ Optional keywords. They have no effect.
+
+
+
+
+
+
+
+
+
+ 1998-09-08
+
+
+ Outputs
+
+
+
+
+
+END
+
+
+ Message returned if the transaction is successfully committed.
+
+
+
+
+
+NOTICE EndTransactionBlock and not inprogress/abort state
+
+
+ If there is no transaction in progress.
+
+
+
+
+
+
+
+
+
+
+ 1998-09-08
+
+
+ Description
+
+
+ synonym for
+ .
+
+
+
+
+ 1998-09-08
+
+
+ Notes
+
+ The keywords WORK and TRANSACTION are noise and can be omitted.
+
+
+ Use
+ to abort a transaction.
+
+
+
+
+
+
+ Usage
+
+ To make all changes permanent:
+
+END WORK;
+
+
+
+
+
+
+ Compatibility
+
+
+
+
+ 1998-09-08
+
+
+ SQL92
+
+
+ extension which provides functionality equivalent to
+ .
+
+
+
+
+
+
+
+
-
+ id="SQL-EXPLAIN-TITLE">
EXPLAIN
SQL - Language Statements
- 1998-09-01
+ 1999-07-20
EXPLAIN [ VERBOSE ] query
Description
+
This command outputs details about the supplied query.
The default output is the computed query cost.
Usage
+
+ To show a query plan for a simple query on a table with a single
+ int4 column and 128 rows:
+
+EXPLAIN SELECT * FROM foo;
+
+NOTICE: QUERY PLAN:
+
+Seq Scan on foo (cost=5.22 rows=128 width=4)
+
+EXPLAIN
+
+
+
+
- To show a query plan for a simple query:
+ For the same table with an index to support an
+ equijoin condition on the query,
+ EXPLAIN will show a different plan:
-EXPLAIN select * from foo;
+EXPLAIN SELECT * FROM foo WHERE i = 4;
+
NOTICE: QUERY PLAN:
-Seq Scan on foo (cost=0.00 rows=0 width=4)
+Index Scan using fi on foo (cost=2.05 rows=1 width=4)
EXPLAIN
+
+
+
+
+ And finally, for the same table with an index to support an
+ equijoin condition on the query,
+ EXPLAIN will show the following for a query
+ using an aggregate function:
+
+EXPLAIN SELECT sum(i) FROM foo WHERE i = 4;
+
+NOTICE: QUERY PLAN:
+
+Aggregate (cost=2.05 rows=1 width=4)
+ -> Index Scan using fi on foo (cost=2.05 rows=1 width=4)
+
Compatibility
-
+
+
-
+ id="SQL-FETCH-TITLE">
FETCH
SQL - Language Statements
- 1998-09-01
+ 1999-07-20
FETCH [ selector ] [ count ] { IN | FROM } cursor
Description
+
- FETCH allows a user to retrieve rows using a cursor.
+ FETCH allows a user to retrieve rows using a cursor.
The number of rows retrieved is specified by
#.
If the number of rows remaining in the cursor is less
- Negative numbers are now allowed to be specified for the
+ Negative numbers are allowed to be specified for the
row count. A negative number is equivalent to reversing
the sense of the FORWARD and BACKWARD keywords. For example,
FORWARD -1 is the same as BACKWARD 1.
- Note that the FORWARD and BACKWARD keywords are
- The
SQL92 syntax is also supported, specified
- in the second form of the command. See below for details
- on compatibility issues.
-
- Once all rows are fetched, every other fetch access returns
- no rows.
-
-
- Updating data in a cursor is not supported by
- because mapping cursor updates back to base tables is
- not generally possible, as is also the case with VIEW updates.
- Consequently,
- users must issue explicit UPDATE commands to replace data.
-
-
- Cursors may only be used inside of transactions because
- the data that they store spans multiple user queries.
-
Notes
+
- Use MOVE to change cursor position.
- DECLARE will define a cursor.
- Refer to BEGIN, COMMIT, and
- ROLLBACK
+ Note that the FORWARD and BACKWARD keywords are
+ The
SQL92 syntax is also supported, specified
+ in the second form of the command. See below for details
+ on compatibility issues.
+
+
+ Once all rows are fetched, every other fetch access returns
+ no rows.
+
+
+ Updating data in a cursor is not supported by
+ because mapping cursor updates back to base tables is
+ not generally possible, as is also the case with VIEW updates.
+ Consequently,
+ users must issue explicit UPDATE commands to replace data.
+
+
+ Cursors may only be used inside of transactions because
+ the data that they store spans multiple user queries.
+
+
+ Use
+
+ to change cursor position.
+
+ will define a cursor.
+ Refer to
+ ,
+ ,
+ and
+
for further information about transactions.
Usage
+
+ The following examples traverses a table using a cursor.
+
--set up and use a cursor:
--
--
FETCH FORWARD 5 IN liahona;
+
code |title |did| date_prod|kind |len
-----+-----------------------+---+----------+----------+------
BL101|The Third Man |101|1949-12-23|Drama | 01:44
JL201|Une Femme est une Femme|102|1961-03-12|Romantic | 01:25
P_301|Vertigo |103|1958-11-14|Action | 02:08
P_302|Becket |103|1964-02-03|Drama | 02:28
-
+
--Fetch previous row:
--
FETCH BACKWARD 1 IN liahona;
+
code |title |did| date_prod|kind |len
-----+-----------------------+---+----------+----------+------
P_301|Vertigo |103|1958-11-14|Action | 02:08
+
-- close the cursor and commit work:
--
Compatibility
- The non-embedded use of cursors is a
Postgres
- extension. The syntax and usage of cursors is being compared
- against the embedded form of cursors defined in
SQL92.
-
SQL92
+
+
+ The non-embedded use of cursors is a
Postgres
+ extension. The syntax and usage of cursors is being compared
+ against the embedded form of cursors defined in
SQL92.
+
+
+
+
SQL92 allows absolute positioning of the cursor for
FETCH, and allows placing the results into explicit variables.
+
+
-
+ id="SQL-GRANT-TITLE">
GRANT
SQL - Language Statements
- 1998-09-23
+ 1999-07-20
GRANT privilege [, ...] ON object [, ...]
Description
+
GRANT allows the creator of an object to give specific permissions to
all users (PUBLIC) or to a certain user or group.
Currently, to create a GROUP you have to insert
data manually into table pg_group as:
+
INSERT INTO pg_group VALUES ('todos');
CREATE USER miriam IN GROUP todos;
Compatibility
-
+
+
-
+ id="APP-INITDB-TITLE">
Application
- 1998-10-02
+ 1999-07-20
initdb [ --pgdata=dbdir | -r dbdir ]
+
+
-
+ id="APP-INITLOCATION-TITLE">
Application
- 1998-10-02
+ 1999-07-20
initlocation [ --location=er">alble> | -D altdir ]
+
+
-
+ id="SQL-INSERT-TITLE">
INSERT
SQL - Language Statements
- 1998-09-23
+ 1999-07-20
INSERT INTO table [ ( column [, ...] ) ]
Description
+
- INSERT allows one to insert new rows into a table. One can insert
+ INSERT allows one to insert new rows into a
+ class or table. One can insert
a single row at time or several rows as a result of a query.
The columns in the target list may be listed in any order.
- In every column not present in the target list will be inserted
- the default value, if column has not a declared default value
- it will be assumed as NULL. If the expression for each column
+
+
+ Each column not present in the target list will be inserted
+ using a default value, either a declared DEFAULT value
+ or NULL.
Postgres will reject the new
+ column if a NULL is inserted into a column declared NOT NULL.
+
+
+ If the expression for each column
is not of the correct data type, automatic type coercion will be
attempted.
+
You must have insert privilege to a table in order to append
to it, as well as select privilege on any table specified
- Insert into arrays (refer to The PostgreSQL User's Guide for further
+ Insert into arrays (refer to
+ The PostgreSQL User's Guide for further
information about arrays):
Compatibility
-
INSERT is fully compatible with
SQL92.
Possible limitations in features of the
query
- clause are documented for the SELECT statement.
+ clause are documented for
+ .
--- /dev/null
+
+
+
+
+
+
+ Application
+
+
+
+
+
+ Clean up shared memory and semaphores from aborted backends
+
+
+
+
+ 1999-07-20
+
+
+ipcclean
+
+
+
+
+ 1999-07-20
+
+
+ Inputs
+
+ None.
+
+
+
+
+
+ 1999-07-30
+
+
+ Outputs
+
+ None.
+
+
+
+
+
+
+ 1999-07-20
+
+
+ Description
+
+ cleans up shared memory and semaphore space from aborted backends by
+ deleting all instances owned by user postgres.
+ Only the DBA
+ should execute this program as it can cause bizarre behavior (i.e.,
+ crashes) if run during multi-user execution. This program should be
+ executed if messages such as
+
+
+semget: No space left on device
+
+
+ are encountered when starting up the
+
postmaster or the backend server.
+
+
+ If this command is executed while
postmaster
+ is running, the shared memory and semaphores allocated by the
+ will be deleted. This will result in a general failure of the
+ backends servers started by that
+
+
+ This script is a hack, but in the many years since it was written, no
+ one has come up with an equally effective and portable solution.
+ Suggestions are welcome.
+
+
+ The script makes assumption about the format of output of the
+ utility which may not be true across different operating systems.
+ Therefore, it may not work on your particular OS.
+
+
+
+
+
+
+
-
+ id="SQL-LISTEN-TITLE">
LISTEN
SQL - Language Statements
- 1998-10-07
+ 1999-07-20
LISTEN name
Description
+
-
LISTEN registers the current
Postgres backend as a
+ LISTEN registers the current
listener on the notify condition
name.
+
Whenever the command
NOTIFY name
frontend application. See the discussion of NOTIFY
for more information.
+
A backend can be unregistered for a given notify condition with the
UNLISTEN command. Also, a backend's listen registrations
are automatically cleared when the backend process exits.
+
The method a frontend application must use to detect notify events depends on
which
Postgres application programming interface it
LISTEN or UNLISTEN directly. See the
documentation for the library you are using for more details.
+
- The reference page for NOTIFY contains a more extensive
+
+ contains a more extensive
discussion of the use of LISTEN and
NOTIFY.
Notes
+
name
can be any string valid as a name;
+
+
-
+ id="SQL-LOAD-TITLE">
LOAD
SQL - Language Statements
- 1998-09-24
+ 1999-07-20
LOAD 'filename'
Description
+
Loads an object (or ".o") file into the
Postgres backend address space. Once a
file is loaded, all functions in that file can be accessed. This
function is used in support of user-defined types and functions.
+
If a file is not loaded using
LOAD,
recompiled. Only objects created from C language files are supported
at this time.
+
1998-09-24
Notes
+
Functions in loaded object files should not call functions in other
object files loaded through the
Compatibility
-
+
+
-
+ id="sql-lock-title">
LOCK
SQL - Language Statements
- 1998-09-24
+ 1999-07-20
LOCK [ TABLE ] table
Compatibility
-
There is no
LOCK TABLE in
SQL92,
which instead uses SET TRANSACTION to specify
- concurrency level on transactions. We support that too; see
+ concurrency levels on transactions. We support that too; see
for details.
+
+
-
+ id="SQL-MOVE-TITLE">
MOVE
SQL - Language Statements
- 1998-09-24
+ 1999-07-20
MOVE [ selector ] [ count ]
not return rows.
- Refer to the FETCH command for details on syntax and usage.
+ Refer to
+
+ for details on syntax and usage.
Notes
+
language extension.
+
- Refer to FETCH for a description
- of valid arguments.
- Refer to DECLARE to declare a cursor.
- Refer to BEGIN WORK, COMMIT WORK,
- ROLLBACK WORK statements
+ Refer to
+
+ for a description of valid arguments.
+ Refer to
+
+ to define a cursor.
+ Refer to
+ ,
+ ,
+ and
+
for further information about transactions.
Compatibility
-
SQL92
- There is no SQL92 MOVE statement.
+ There is no
SQL92 MOVE statement.
one to FETCH rows from an absolute cursor position,
- implicitly moving the cursor to the correct place.
+ implicitly moving the cursor to the correct position.
+
+
- ref">
+ title">
NOTIFY
SQL - Language Statements
- 1998-10-07
+ 1999-07-20
NOTIFY name
Compatibility
-
-
+
+
+
- pg-dump">
+ app-pgdump-title">
Application
- 1998-11-05
+ 1999-07-20
pg_dump [ dbname ]
-
+
+
+
-
+ id="APP-PGDUMPALL-TITLE">
Application
- 1998-10-04
+ 1999-07-20
pg_dumpall
Refer to
- pg-dump" linkend="app-pg-dump">
+ app-pgdump-title" linkend="app-pgdump-title">
for more information on this capability.
--- /dev/null
+
+
+
+
+
+
+ Application
+
+
+
+
+
+ Manipulate the flat password file
+
+
+
+
+ 1999-07-20
+
+
+pg_passwd filename
+
+
+
+
+
+ 1999-07-20
+
+
+ Description
+
+ is a tool to manipulate the
+ flat password file functionality of
+
Postgres. This style of password
+ authentication is not required in an
+ installation, but is one of several supported security mechanisms.
+
+
+ Specify the password file in the same style of
+ Ident authentication in
+ $PGDATA/pg_hba.conf:
+
+host unv 133.65.96.250 255.255.255.255 password passwd
+
+
+ where the above line allows access from 133.65.96.250 using the passwords listed
+ in $PGDATA/passwd.
+ The format of the password file follows those of
+ /etc/passwd
+ and
+ /etc/shadow.
+ The first field is the user name, and the second field
+ is the encrypted password.
+ The rest is completely ignored.
+ Thus the following three sample lines specify the same user and password pair:
+
+pg_guest:/nB7.w5Auq.BY:10031::::::
+pg_guest:/nB7.w5Auq.BY:93001:930::/home/guest:/bin/tcsh
+pg_guest:/nB7.w5Auq.BY:93001
+
+
+
+ Supply the password file to the pg_passwd command.
+ In the case described above, after changing the working directory to
+ PGDATA, the following command execution specify
+ the new password for pg_guest:
+
+ % pg_passwd passwd
+ Username: pg_guest
+ Password:
+ Re-enter password:
+
+
+ where the Password:
+ and Re-enter password:
+ prompts require the same password input which are not displayed
+ on the terminal.
+ The original password file is renamed to
+ passwd.bk.
+
+
+ uses the
+ option to invoke this style of
+ authentication.
+
+
+ The following lines show the sample usage of the option:
+
+% psql -h hyalos -u unv
+Username: pg_guest
+Password:
+Welcome to the POSTGRESQL interactive sql monitor:
+ Please read the file COPYRIGHT for copyright terms of POSTGRESQL
+ type \? for help on slash commands
+ type \q to quit
+ type \g or terminate with semicolon to execute query
+ You are currently connected to the database: unv
+unv=>
+
+
+
+ Perl5 authentication
+ uses the new style of the Pg.pm like this:
+
+$conn = Pg::connectdb("host=hyalos dbname=unv
+ user=pg_guest password=xxxxxxx");
+
+
+ For more details, refer to
+ src/interfaces/perl5/Pg.pm.
+
+
+ Pg{tcl,tk}sh authentication
+ uses the
+ pg_connect
+ command with the
+
+ option thusly:
+
+% set conn [pg_connect -conninfo \\
+ "host=hyalos dbname=unv \\
+ user=pg_guest password=xxxxxxx "]
+
+
+ You can list all of the keys for the option by executing the following
+ command:
+
+% puts [ pg_conndefaults]
+
+
+
+
+
+
+
+
-
+ id="APP-PG-UPGRADE-TITLE">
Application
Allows upgrade from a previous release without reloading data
+
- 1998-10-04
+ 1999-07-20
pg_upgrade
Description
+
is a utility for upgrading from a previous
PostgreSQL release without reloading all the data.
+ Not all
Postgres releases can be handled
+ this way; check the release notes for details on your installation.
+
You can delete the data.old/ directory when you
are finished.
+
+
+
+
-
+ id="APP-POSTGRES-TITLE">
Application
- 1999-05-19
+ 1999-07-20
postgres [ dbname ]
+
+
-
+ id="APP-POSTMASTER-TITLE">
Application
- 1999-05-19
+ 1999-07-20
postmaster [ -B nBuffers ] [ -D DataDir ] [ -i ]
+
+
- psql-ref">
+ app-psql-title">
Application
- 1998-09-26
+ 1999-07-20
psql [ dbname ]
+
+
-
+ id="SQL-RESET-TITLE">
RESET
SQL - Language Statements
- 1998-09-24
+ 1999-07-20
RESET variable
variable
- Refer to the SET statement for more information on available
+ Refer to
+
+ for more information on available
variables.
RESET restores variables to the
default values.
- Refer to the SET command for details on
- allowed values and defaults.
+ Refer to
+
+ for details on allowed values and defaults.
RESET is an alternate form for
- SET variable = DEFAULT
+
+
+SET variable = DEFAULT
+
Notes
+
-
The RESET statement is a
Postgres
language extension.
+
- Refer to SET/SHOW statements to set/show variable values.
+ Use to
+ and
+
+ to manipulate variable values.
+
+
-
+ id="SQL-REVOKE-TITLE">
REVOKE
SQL - Language Statements
- 1998-09-24
+ 1999-07-20
REVOKE privilege [, ...]
Privilege to define rules on table/view.
- (See CREATE RULE).
+ (See
+ ).
SQL92
+
The SQL92 syntax for REVOKE
has additional capabilities for rescinding
- Refer to GRANT for details on individual fields.
+ Refer to
+
+ for details on individual fields.
Rescinds authority for a user to grant the specified privilege
to others.
- Refer to the GRANT command for details
- on individual fields.
+ Refer to
+
+ for details on individual fields.
+
+
- 1998-09-24
+ 1999-07-20
ROLLBACK [ WORK | TRANSACTION ]
Use
to successfully terminate a transaction.
+ is a
+ synonym for ROLLBACK.
Compatibility
-
+
+
- 1998-09-24
+ 1999-07-20
SELECT [ ALL | DISTINCT [ ON column ] ]
WHERE Clause
+
The optional WHERE condition has the general form:
-WHERE expr ETER">ce"PARreplaceable> [ log_op ... ]
+WHERE boolean_expr
- where cond_op can be
- one of: =, <, <=, >, >= or <>,
- a conditional operator like ALL, ANY, IN, LIKE, et cetera or a
+ boolean_expr
+ can consist of any expression which evaluates to a boolean value.
+ In many cases, this expression will be
+
+
+ expr cond_op expr
+
+
+ or
+
+
+ log_op expr
+
+
+ where cond_op
+ can be one of: =, <, <=, >, >= or <>,
+ a conditional operator like ALL, ANY, IN, LIKE, or a
locally-defined operator,
and log_op can be one
of: AND, OR, NOT.
Compatibility
-
+
+
-
+ id="SQL-SELECTINTO-TITLE">
SELECT INTO
SQL - Language Statements
- 1998-09-22
+ 1999-07-20
SELECT [ ALL | DISTINCT ] expression [ AS name ] [, ...]
- CREATE TABLE AS is functionally equivalent to the SELECT INTO command.
+
+ is functionally equivalent to the SELECT INTO command.
+
+
-
+ id="SQL-SET-TITLE">
SET
SQL - Language Statements
- id="SQL-SET-TITLE">
+
SET
- 1998-09-24
+ 1999-07-20
SET variable { TO | = } { 'value' | DEFAULT }
Compatibility
-
+
+
-
+ id="SQL-SHOW-TITLE">
SHOW
SQL - Language Statements
- 1998-09-24
+ 1999-07-20
SHOW keyword
Compatibility
-
+
+
- ref" linkend="sql-notify">
+ title" linkend="sql-notify-title">
contains a more extensive
discussion of the use of LISTEN and
NOTIFY.
+
+
-
+ id="SQL-UPDATE-TITLE">
UPDATE
SQL - Language Statements
- 1998-09-24
+ 1999-07-20
UPDATE table SET R">colle> = expression [, ...]
UPDATE changes the values of the columns specified for
all rows which satisfy condition. Only the columns
- to be modified need appear as column.
+ to be modified need appear as columns in the statement.
- Array references use the same syntax found in SELECT.
+ Array references use the same syntax found in
+ .
That is, either single array elements, a range of array
elements or the entire array may be replaced with a single
query.
Compatibility
-
SQL92
- SQL92 defines a different syntax for positioned UPDATE statement:
+
SQL92 defines a different syntax for
+ the positioned UPDATE statement:
UPDATE table SET column = expression [, ...]
-
+
+
+
- vacuum">
+ sql-vacuum-title">
VACUUM
SQL - Language Statements
- 1998-10-04
+ 1999-07-20
VACUUM [ VERBOSE ] [ ANALYZE ] [ table ]
Compatibility
+
1998-10-04
SQL92
- There is no VACUUM statement in SQL92.
+ There is no
VACUUM statement in
SQL92.
+
+
-
+ id="APP-VACUUMDB-TITLE">
Application
- See vacuum" linkend="vacuum"> for more details.
+ See sql-vacuum-title" linkend="sql-vacuum-title"> for more details.