- 1998-04-15
+ 1998-09-11
- CREATE TABLE table (
- column type [DEFAULT value] [CONSTRAINT column_constraint] [, ...]
- [, column ...]
- [, CONSTRAINT table_constraint]
- ) [INHERITS ( inherited_table [, ...] )]
+CREATE TABLE table (
+ column type [ DEFAULT value | column_constraint_clause | PRIMARY KEY } [ ... ] ]
+ [, ... ]
+ [, PRIMARY KEY ( column [, ...] ) ]
+ [, table_constraint_clause ]
+ ) [ INHERITS ( inherited_table [, ...] ) ]
- 1998-04-15
+ 1998-09-11
Inputs
-
- The type of the column.
-
(Refer to the Postgres User's Guide for
- further information about data types).
+ The type of the column. This may include array specifiers.
+ Refer to the PostgreSQL User's Guide for
+ further information about data types and arrays.
- value
+ DEFAULT value
- CLASS="PARAMETER">inherited_table
+ >column_constraint_clause
- The optional INHERITS clause specifies a collection of table
- names from which this table automatically inherits all fields.
- If any inherited field name appears more than once, PostgreSQL
- reports an error. PostgreSQL automatically allows the created
- table to inherit functions on tables above it in the inheritance
- hierarchy. Inheritance of functions is done according
- to the conventions of the Common Lisp Object System (CLOS).
+ The optional column constraint clause specifies a list of integrity
+ constraints which new or updated entries must satisfy for
+ an insert or update operation to succeed. Each constraint
+ must evaluate to a boolean expression. Although
SQL92
+requires the column_constraint_clause
+ to refer to that column only,
Postgres
+ allows multiple columns
+ to be referenced within a single column constraint.
+ See the column constraint clause for more information.
-
+
- column_constraint
- table_constraint
+ table_constraint_clause
- The optional CONSTRAINT clause specifies a list of integrity
+ The optional table CONSTRAINT clause specifies a list of integrity
constraints which new or updated entries must satisfy for
an insert or update operation to succeed. Each constraint
must evaluate to a boolean expression. Multiple columns
may be referenced within a single constraint.
- See CONSTRAINT clause for more information.
+ See the table constraint clause for more information.
+
+
+
+ INHERITS inherited_table
+
+
+ The optional INHERITS clause specifies a collection of table
+ names from which this table automatically inherits all fields.
+ If any inherited field name appears more than once,
+ reports an error.
+
Postgres automatically allows the created
+ table to inherit functions on tables above it in the inheritance
+ hierarchy.
+
+
Aside
+ Inheritance of functions is done according
+ to the conventions of the Common Lisp Object System (CLOS).
+
+
+
+
+
- 1998-04-15
+ 1998-09-11
Outputs
Message returned if table creation failed.
This is usually accompanied by some descriptive text, such as:
- amcreate: "table" relation already exists
+amcreate: "table" relation already exists
which occurs at runtime, if the table specified already exists
in the database.
+
+
+
+ ERROR: DEFAULT: type mismatched
+
+
+ if data type of default value doesn't match the
+ column definition's data type.
+
+
+
+
- 1998-04-15
+ 1998-09-11
Description
- CREATE TABLE will enter a new table into the current data
+ CREATE TABLE will enter a new table into the current data
base. The table will be "owned" by the user issuing the
command.
a system catalog table.
-
-
- 1998-04-15
-
+
+
+
+ 1998-09-11
+
- DEFAULT clause
+ DEFAULT Clause
- DEFAULT value
+DEFAULT value
- The DEFAULT clause assigns a default data value to a column.
- </PARA>
- >
- >
- >
-
- >
+
+
+ <REFSECT2INFO>
+ 1998-09-11>
+ >
+ >
+ Inputs
+ >
- valuee>
+ valuee>
- The possible values for expression are:
+ The possible values for the default value expression are:
-
-
- ERROR: DEFAULT: type mismatched
-
-
- if data type of default value doesn't match the
- column definition's data type.
-
-
-
+
+
+ 1998-09-11
+
+
+ Outputs
+
+
+
+
+ 1998-09-11
+
+
+ Description
+
The DEFAULT clause assigns a default data value to a column
(via a column definition in the CREATE TABLE statement).
The data type of a default value must match the column definition's
is the value of the specified function at the time of the INSERT.
- There are two types of niladic functions:
+ There are two types of niladic functions:
+
niladic USER
-
-
-
-
-
-
+
+In the current release (v6.4),
Postgres
+evaluates all default expressions at the time the table is defined.
+Hence, functions which are "non-cacheable" such as
+ CURRENT_TIMESTAMP may not produce the desired
+effect. For the particular case of date/time types, one can work
+around this behavior by using
+
+DEFAULT TEXT 'now'
+
+instead of
+
+DEFAULT 'now'
+
+or
+
+DEFAULT CURRENT_TIMESTAMP
+.
+This forces
Postgres to consider the constant a string
+type and then to convert the value to timestamp at runtime.
+
+
- 1998-04-15
+ 1998-09-11
- NOT NULL constraint
+ Usage
+
+ To assign a constant value as the default for the
+ columns did and number,
+ and a string literal to the column did:
+
+CREATE TABLE video_sales (
+ did VARCHAR(40) DEFAULT 'luso films',
+ number INTEGER DEFAULT 0,
+ total CASH DEFAULT '$0.0'
+);
+
+
+ To assign an existing sequence
+ as the default for the column did,
+ and a literal to the column name:
+
+CREATE TABLE distributors (
+ did DECIMAL(3) DEFAULT NEXTVAL('serial'),
+ name VARCHAR(40) DEFAULT 'luso films'
+);
+
+
+
+
+
+
+ 1998-09-11
+
+
+ Column CONSTRAINT Clause
- [ CONSTRAINT name ] NOT NULL
+[ CONSTRAINT name ] { NOT NULL | UNIQUE | PRIMARY KEY | CHECK constraint } [, ...]
+
+
+
+ 1998-09-11
+
+
+ Inputs
+
- The NOT NULL constraint specifies a rule that a column may
- contain only non-null values.
-
- The NOT NULL constraint is a column constraint.
-
-
+
+
+
+ name
+
+
+ An arbitrary name given to the integrity constraint.
+If name is not specified,
+ it is generated from the table and column names,
+which should ensure uniqueness for
+ name.
+
+
+
+
+ NOT NULL
-
+The column is not allowed to contain NULL values.
+This is equivalent to the column constraint
+ CHECK (column NOT NULL).
+
+
+
+
+
+
+ UNIQUE
+
+
+The column must have unique values. In
Postgres
+this is enforced by an implicit creation of a unique index on the table.
+
+
+
+
+
+
+ PRIMARY KEY
+
+
+ This column is a primary key, which implies that uniqueness is
+enforced by the system and that other tables may rely on this column
+as a unique identifier for rows.
+ See PRIMARY KEY for more information.
+
+
+
+
- namee>
+ constrainte>
- The optional name of a constraint.
+ The definition of the constraint.
-
-
-
-
-
+
+
+
+
+ 1998-09-11
+
+
+ Description
+
+ 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
+ UNIQUE
+ CHECK
+ NOT NULL
+
+
+(at release 6.4) support
+ REFERENCES integrity constraints. The parser
+accepts the REFERENCES syntax but ignores the clause.
+
+
+
+
+
+ 1998-09-11
+
+
+ NOT NULL Constraint
+
+
+[ CONSTRAINT name ] NOT NULL
+
+ The NOT NULL constraint specifies a rule that a column may
+ contain only non-null values.
+
+ The NOT NULL constraint is a column constraint only, and not allowed
+as a table constraint.
+
+
- 1998-04-15
+ 1998-09-11
Outputs
+status
+
+
+
+ 1998-09-11
+
+
+Description
+
+
+
+
+ 1998-09-11
+
+
+Usage
+
+
+ Define two NOT NULL column constraints on the table
+ distributors,
+one of which being a named constraint:
+
+CREATE TABLE distributors (
+ did DECIMAL(3) CONSTRAINT no_null NOT NULL,
+ name VARCHAR(40) NOT NULL
+);
+
+
+
+
+ 1998-09-11
+
+
+ UNIQUE Constraint
+
+
+[ CONSTRAINT name ] UNIQUE
+
+
+
+
Inputs
+
+
+
+ CONSTRAINT name
+
+
+ An arbitrary label given to a constraint.
+
+
+
+
+
+
+
+
Outputs
+
+
+
+status
+
+
+
+
+
+ERROR: Cannot insert a duplicate key into a unique index.
+
+
+ This error occurs at runtime if one tries to insert a
+ duplicate value into a column.
+
+
+
+
+
+
+
+
+
+
+
+Description
+
+
+ The UNIQUE constraint specifies a rule that a group of one or
+ more distinct columns of a table may contain only unique values.
+
+ The column definitions of the specified columns do not have to
+ include a NOT NULL constraint to be included in a UNIQUE
+ constraint. Having more than one null value in a column without a
+ NOT NULL constraint, does not violate a UNIQUE constraint.
+(This deviates from the
SQL92 definition, but
+is a more sensible convention. See the section on compatibility
+for more details.).
+
+ Each UNIQUE column constraint must name a column that is
+ different from the set of columns named by any other UNIQUE or
+ PRIMARY KEY constraint defined for the table.
+
+
+
Postgres automatically creates a unique
+ index for each UNIQUE constraint, to assure
+ data integrity. See CREATE INDEX for more information.
+
+
+
+
+
+Usage
+
+
+ Defines a UNIQUE column constraint for the table distributors.
+ UNIQUE column constraints can only be defined on one column
+ of the table:
+ CREATE TABLE distributors (
+ did DECIMAL(3),
+ name VARCHAR(40) UNIQUE
+ );
+
+which is equivalent to the following specified as a table constraint:
+CREATE TABLE distributors (
+ did DECIMAL(3),
+ name VARCHAR(40),
+ UNIQUE(name)
+);
+
+
+
+
+ 1998-09-11
+
+
+The CHECK Constraint
+
+
+[ CONSTRAINT name ] CHECK ( condition [, ...] )
+
+
+
Inputs
+
+
+
+ name
+
+
+ An arbitrary name given to a constraint.
+
+
+
+
+
+ condition
+
+
+ Any valid conditional expression evaluating to a boolean result.
+
+
+
+
+
+
+
+ 1998-09-11
+
+
+ Outputs
+
+
+
+
+status
+
+
+
+
+
+
+
+ ERROR: ExecAppend: rejected due to CHECK constraint
+ "table_column".
+
+
+
+ This error occurs at runtime if one tries to insert an illegal
+ value into a column subject to a CHECK constraint.
+
+
+
+
+
+
+
+
+
+
+
Description
+ The CHECK constraint specifies a restriction on allowed values
+within a column.
+ The CHECK constraint is also allowed as a table constraint.
+
+ The SQL92 CHECK column constraints can only be defined on, and
+ refer to, one column of the table.
Postgres
+ does not have
+ this restriction.
+
+
-
+
+
+ 1998-09-11
+
+
+ PRIMARY KEY Constraint
+
+
+[ CONSTRAINT name ] PRIMARY KEY
+
+
+
+
Inputs
+
+
+
+CONSTRAINT name
+
+
+ An arbitrary name for the constraint.
+
+
+
+
+
+
+
+
+
Outputs
+
+
+
+ERROR: Cannot insert a duplicate key into a unique index.
+
+
+ This occurs at run-time if one tries to insert a duplicate value into
+ a column subject to a PRIMARY KEY constraint.
+
+
+
+
+
+
+
+
Description
+ The PRIMARY KEY column constraint specifies that a column of a table
+ may contain only unique
+ (non-duplicate), non-NULL values. The definition of
+ the specified column does not have to include an explicit NOT NULL
+ constraint to be included in a PRIMARY KEY constraint.
+
+ Only one PRIMARY KEY can be specified for a table.
+
+
+
+
+
+ 1998-09-11
+
+
+ Notes
+
+
Postgres automatically creates
+ a unique index to assure
+ data integrity. (See CREATE INDEX statement)
+
+ The PRIMARY KEY constraint should name a set of columns that is
+ different from other sets of columns named by any UNIQUE constraint
+ defined for the same table, since it will result in duplication
+of equivalent indexes and unproductive additional runtime overhead.
+However,
Postgres does not specifically
+disallow this.
+
+
+
+
+
+ 1998-09-11
+
+
+ Table CONSTRAINT Clause
+
+
+[ CONSTRAINT name ] { PRIMARY KEY | UNIQUE } ( column [, ...] )
+[ CONSTRAINT name ] CHECK ( constraint )
+
+
+
+
+ 1998-09-11
+
+
+Inputs
+
+
+
+
+
+ CONSTRAINT name
+
+
+ An arbitrary name given to an integrity constraint.
+
+
+
+
+
+ column [, ...]
+
+
+ The column name(s) for which to define a unique index
+and, for PRIMARY KEY, a NOT NULL constraint.
+
+
+
+
+ CHECK ( constraint )
+
+
+ A boolean expression to be evaluated as the constraint.
+
+
+
+
+
+
+
+ 1998-09-11
+
+
+Outputs
+
+
+The possible outputs for the table constraint clause are the same
+as for the corresponding portions of the column constraint clause.
+
+
+
+ 1998-09-11
+
+
+Description
+
+
+ A table constraint is an integrity constraint defined on one or
+ more columns of a base table. The four variations of "Table
+ Constraint" are:
+
+ UNIQUE
+ CHECK
+ PRIMARY KEY
+ FOREIGN KEY
+
+
+
+(as of version 6.4) support FOREIGN KEY
+integrity constraints. The parser understands the FOREIGN KEY syntax,
+but only prints a notice and otherwise ignores the clause.
+ Foreign keys may be partially emulated by triggers (See the CREATE TRIGGER
+ statement).
+
+
+
+
- 1998-04-15
+ 1998-09-11
- UNIQUE constraint
+ UNIQUE Constraint
- Table Constraint definition
-
-
- [ CONSTRAINT name ] UNIQUE ( column [, ...] )
-
- Column Constraint definition
-
- [ CONSTRAINT name ] UNIQUE
+[ CONSTRAINT name ] UNIQUE ( column [, ...] )
-
Parameters
+
Inputs
- name
+ CONSTRAINT name
Outputs
-
+status
-
+
+
-
Description
+
+Description
+
+
The UNIQUE constraint specifies a rule that a group of one or
more distinct columns of a table may contain only unique values.
+The behavior of the UNIQUE table constraint is the same as that for column
+constraints, with the additional capability to span multiple columns.
- The column definitions of the specified columns do not have to
- include a NOT NULL constraint to be included in a UNIQUE
- constraint. Having more than one null value in a column without a
- NOT NULL constraint, does not violate a UNIQUE constraint.
-
- Each UNIQUE constraint must name a set of columns that is
- different from the set of columns named by any other UNIQUE or
- PRIMARY KEY constraint defined for the Table.
-
-
- PostgreSQL automatically creates a unique index for each UNIQUE
- constraint, to assure
- data integrity. See CREATE INDEX for more information.
-
-
-
-
-
-
- 1998-04-15
-
+See the section on the UNIQUE column constraint for more details.
+
+
- CONSTRAINT clause
-
- Table constraint definition
-
-
- [ CONSTRAINT name ]
- { PRIMARY KEY constraint |
- UNIQUE constraint |
- CHECK constraint }
-
- Column constraint definition
-
-
- [ CONSTRAINT name ]
- { NOT NULL constraint |
- PRIMARY KEY constraint |
- UNIQUE constraint |
- CHECK constraint }
-
-
-
-
-
-
-
-
-
-
-
- name
-
-
-
- An arbitrary name given to an integrity constraint.
-
-
-
-
-
-
- constraint
-
-
-
- The definition of the constraint.
-
-
-
-
-
-
-
- A Constraint is a named rule: a 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 constraint and Column constraint.
-
- A Table Constraint is an integrity Constraint defined on one or
- more Columns of a Base table. The four variations of "Table
- Constraint" are:
-
- PRIMARY KEY
- FOREIGN KEY
- UNIQUE
- CHECK
-
-
- 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
- UNIQUE
- CHECK
- NOT NULL
-
-
- PostgreSQL does not yet (at release 6.3.2) support the FOREIGN KEY or
- REFERENCES integrity constraints, although the parser will accept them.
- Foreign keys may be partially emulated by triggers (See CREATE TRIGGER
- statement)
-
-
-
- PostgreSQL does not yet support either DOMAINs or ASSERTIONs.
-
-
-
-
-
-
-
- 1998-04-15
-
-
The CHECK constraint
-
- [ CONSTRAINT name ] CHECK ( condition [, ...] )
-
-
-
Inputs
-
-
-
- name
-
-
- An arbitrary name given to a constraint.
-
-
-
-
-
- condition
-
-
- Any valid conditional expression.
-
-
-
-
-
+Usage
+
+
+ Define a UNIQUE table constraint for the table distributors:
+CREATE TABLE distributors (
+ did DECIMAL(03),
+ name VARCHAR(40),
+ UNIQUE(name)
+);
+
+
-
-
- 1998-04-15
-
-
- Outputs
-
-
-
-
-
- ERROR: ExecAppend: rejected due to CHECK constraint
- "table_column".
-
-
-
- This error occurs at runtime if one tries to insert an illegal
- value into a column subject to a CHECK constraint.
-
-
-
-
-
-
-
Description
- The CHECK constraint specifies a rule that a group of one or
- more columns of a table may contain only those values allowed by
- the rule.
- The CHECK constraint is either a table constraint or a column
- constraint.
-
- PostgreSQL automatically creates an unique index to assure
- data integrity (See CREATE INDEX statement).
- The SQL92 CHECK column constraints can only be defined on, and
- refer to, one column of the table. PostgreSQL does not have
- this restriction.
-
-
-
- 1">
+
+ 4">
- 1998-04-15
+ 1998-09-11
- PRIMARY KEY clause
+ PRIMARY KEY Constraint
- Table constraint definition
-
[ CONSTRAINT name ] PRIMARY KEY ( column [, ...] )
- Column constraint definition
-
-
- [ CONSTRAINT name ] PRIMARY KEY
-
-
Parameters
+
Inputs
- name
+CONSTRAINT name
- column
+column [, ...]
- The name of a column in the table.
+ The names of one or more columns in the table.
+
Outputs
+
+
+
+status
+
+
ERROR: Cannot insert a duplicate key into a unique index.
+
+
+
+
Description
The PRIMARY KEY constraint specifies a rule that a group of one
or more distinct columns of a table may contain only unique,
- (not duplicates), non-null values. The column definitions of
+ (non duplicate), non-null values. The column definitions of
the specified columns do not have to include a NOT NULL
- constraint to be included in a PRIMARY KEY constraint.
-
- A table's set of valid values may be constrained by only one
- PRIMARY KEY constraint at a time.
+ constraint to be included in a PRIMARY KEY constraint.
+
+The PRIMARY KEY table constraint is similar to that for column constraints,
+with the additional capability of encompassing multiple columns.
- The PRIMARY KEY constraint must name a set of columns that is
- different from the set of columns named by any UNIQUE constraint
- defined for the same table.
-
+Refer to the section on the PRIMARY KEY column constraint for more
+information.
-
-
- 1998-04-15
-
-
- Notes
-
- PostgreSQL automatically creates an unique index to assure
- data integrity. (See CREATE INDEX statement)
-
-
-
+
);
- Define two NOT NULL column constraints on the table distributors
-
- CREATE TABLE distributors (
- did DECIMAL(3) CONSTRAINT no_null NOT NULL,
- name VARCHAR(40) NOT NULL
- );
-
-
Define a UNIQUE table constraint for the table films.
UNIQUE table constraints can be defined on one or more
);
- Defines a UNIQUE column constraint for the table distributors.
- UNIQUE column constraints can only be defined on one column
- of the table (the following two examples are equivalents).
-
- CREATE TABLE distributors (
- did DECIMAL(03),
- name VARCHAR(40) UNIQUE,
- UNIQUE(name)
- );
-
-
- CREATE TABLE distributors (
- did DECIMAL(3),
- name VARCHAR(40) UNIQUE
- );
-
-
Define a CHECK column constraint.
Defines a PRIMARY KEY column constraint for table distributors.
PRIMARY KEY column constraints can only be defined on one column
- of the table (the following two examples are equivalents)
+ of the table (the following two examples are equivalent)
CREATE TABLE distributors (
name VARCHAR(40)
);
- To assign a sequence as the default for the column did,
- and a literal to the column name
-
-
- CREATE TABLE distributors (
- did DECIMAL(3) DEFAULT NEXTVAL('serial'),
- name VARCHAR(40) DEFAULT 'luso films'
- );
-
- 1998-04-15
+ 1998-09-11
Notes
- CREATE TABLE/INHERITS is a PostgreSQL language extension.
+ CREATE TABLE/INHERITS is a
Postgres
+ language extension.
Compatibility
-
- 1998-04-15
+ 1998-09-11
SQL92
- In addition to normal CREATE TABLE, SQL92 also defines a
+ In addition to the normal CREATE TABLE, SQL92 also defines a
CREATE TEMPORARY TABLE statement:
) ON COMMIT DELETE ROWS
-Temporary tables are not currently available in
Postgres.
+Temporary tables are not currently available
- In the current release of
Postgres (v6.4), to create a temporary
+ In the current release of
Postgres
+ (v6.4), to create a temporary
table you must create and drop the table by explicit commands.
- 1998-04-15
+ 1998-09-11
UNIQUE clause
- 1998-04-15
+ 1998-09-11
NOT NULL clause
- 1998-04-15
+ 1998-09-11
DEFAULT clause
- 1998-04-15
+ 1998-09-11
CONSTRAINT clause
- SQL92 specifies some additional capabilities for CONSTRAINTs,
+ SQL92 specifies some additional capabilities for constraints,
and also defines assertions and domain constraints.
-
+
+
Postgres does not yet support
+either domains or assertions.
+
+
+
An assertion is a special type of integrity constraint and share
the same namespace as other constraints.
- 1998-04-15
+ 1998-09-11
CHECK clause
- 1998-04-15
+ 1998-09-11
PRIMARY KEY clause
- 1998-04-15
+ 1998-09-21
- CREATE TYPE typename (
- INTERNALLENGTH = (internallength | VARIABLE)
- [, EXTERNALLENGTH = (externallength | VARIABLE) ]
+CREATE TYPE typename (
Why are parentheses required around the length parameters?
- , INPUT = input_function
- , OUTPUT = output_function
- [, ELEMENT = element]
- [, DELIMITER = delimiter]
- [, DEFAULT = "default" ]
- [, SEND = send_function ]
- [, RECEIVE = receive_function ]
- [, PASSEDBYVALUE])
+ 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 ]
+)
- 1998-04-15
+ 1998-09-21
Inputs
-
-
-
-
-
-
typename
-
-
- internallength
-
+INTERNALLENGTH internallength
-
- externallength
-
+EXTERNALLENGTH externallength
-
- input_function
-
+ INPUT input_function
-
- output_function
-
+ OUTPUT output_function
-
element
-
-
delimiter
-
-
default
- >
-
send_function
-
-
receive_function
-
-
-
-
- 1998-04-15
+ 1998-09-21
Outputs
+status
- 1998-04-15
+ 1998-09-21
Description
- 1998-04-15
+ 1998-09-21
Notes
- Refer to DROP TYPE statement to drop types.
+ Refer to DROP TYPE to remove an existing type.
- See also CREATE FUNCTION, CREATE OPERATOR and large_objects.
+ See also CREATE FUNCTION,
+ CREATE OPERATOR and the chapter on Large Objects
+in the PostgreSQL Programmer's Guide.
+
Compatibility
- CREATE TYPE statement is a PostgreSQL language extension.
-
- 1998-04-15
+ 1998-09-21
SQL3
- CREATE TYPE is a SQL3 statement.
+
CREATE TYPE is an SQL3 statement.
- 1998-04-15
+ 1998-09-21
-
- CREATE USER username
- [WITH PASSWORD password]
- [CREATEDB | NOCREATEDB]
- [CREATEUSER | NOCREATEUSER]
- [IN GROUP groupname [, ...] ]
- [VALID UNTIL 'abstime']
-
-
+CREATE USER username
+ [ WITH PASSWORD password ]
+ [ CREATEDB | NOCREATEDB ]
+ [ CREATEUSER | NOCREATEUSER ]
+ [ IN GROUP groupname [, ...] ]
+ [ VALID UNTIL 'abstime' ]
- 1998-04-15
+ 1998-09-21
Inputs
-
-
-
-
-
-
The WITH PASSWORD clause sets the user's password within
the "pg_shadow" table. For this reason,
"pg_shadow" is no
- longer accessible to the instance of PostgreSQL that the
- PostgreSQL user's password is initially set to NULL.
+ longer accessible to the instance of
Postgres that the
+
Postgres user's password is initially set to NULL.
The text here has got garbled.
When a
user's password in the "pg_shadow"
authentication proceeds as it historically has (HBA,
PG_PASSWORD, etc). However, if a password is set for a
user, a new authentication system supplants any other
- configured for the PostgreSQL instance, and the password
+ configured for the
Postgres instance, and the password
stored in the "pg_shadow" table is used
for authentication.
For more details on how this authentication system
These clauses determine whether a user will be permitted to
create new
- users in an instance of PostgreSQL.
+ users in an instance of
Postgres.
Omitting this clause will set the user's value of this
attribute to be NOCREATEUSER.
The VALID UNTIL clause sets an absolute time after which the
- user's PostgreSQL login is no longer valid. Please note that
+ user's
Postgres login is no longer valid. Please note that
if a user does not have a password defined in the
"pg_shadow"
table, the valid until date will not be checked
-
-
-
- 1998-04-15
+ 1998-09-21
Outputs
+status
- 1998-04-15
+ 1998-09-21
Description
- CREATE USER will add a new user to an instance of PostgreSQL.
+ CREATE USER will add a new user to an instance of
The new user will be given a usesysid of:
'SELECT MAX(usesysid) + 1 FROM pg_shadow'.
This means that
- PostgreSQL users' usesysids will not
+
Postgres users'
usesysids will not
correspond to their operating
system(OS) user ids. The exception to this rule is
the 'postgres' user, whose OS user id
If you still want the
OS user id and the usesysid to match
for any given user,
- use the "createuser" script provided with the PostgreSQL
+ use the "createuser" script provided with the
Postgres
distribution.
- 1998-04-15
+ 1998-09-21
Notes
- CREATE USER statement is a PostgreSQL language extension.
+ CREATE USER statement is a
Postgres language extension.
Use DROP USER or ALTER USER statements to remove or modify a user
- 1998-04-15
+ 1998-09-21
SQL92
- 1998-04-15
+ 1998-09-21
- CREATE VIEW view
- AS SELECT query
+CREATE VIEW view
+ AS SELECT query
- 1998-04-15
+ 1998-09-21
Inputs
-
-
-
-
-
-
-
-
-
- 1998-04-15
+ 1998-09-21
Outputs
+status
- 1998-04-15
+ 1998-09-21
Description
- 1998-04-15
+ 1998-09-21
Notes
- 1998-04-15
+ 1998-09-21
Bugs
Create a view consisting of all Comedy films:
- CREATE VIEW kinds AS
- SELECT *
- FROM films
- WHERE kind = 'Comedy';
+CREATE VIEW kinds AS
+ SELECT *
+ FROM films
+ WHERE kind = 'Comedy';
- SELECT * FROM kinds;
+SELECT * FROM kinds;
- code |title |did| date_prod|kind |len
- -----+-------------------------+---+----------+----------+------
- UA502|Bananas |105|1971-07-13|Comedy | 01:22
- C_701|There's a Girl in my Soup|107|1970-06-11|Comedy | 01:36
+code |title |did| date_prod|kind |len
+-----+-------------------------+---+----------+----------+------
+UA502|Bananas |105|1971-07-13|Comedy | 01:22
+C_701|There's a Girl in my Soup|107|1970-06-11|Comedy | 01:36
- 1998-04-15
+ 1998-09-21
SQL92
SQL92 specifies some additional capabilities for the CREATE VIEW statement:
- <programlisting>
- CREATE VIEW view [ column [, ...] ]
- AS SELECT expression [AS colname] [, ...]
- FROM table
- [WHERE condition]
- [ WITH [ CASCADE | LOCAL ] CHECK OPTION ]
- programlisting>
+ <synopsis>
+CREATE VIEW view [ column [, ...] ]
+ AS SELECT expression [AS colname] [, ...]
+ FROM table
+ [ WHERE condition ]
+ [ WITH [ CASCADE | LOCAL ] CHECK OPTION ]
+ synopsis>
- CHECK OPTION
+ CHECK OPTION
This option is to do with updatable views.
- LOCAL
+ LOCAL
- CASCADE
+ CASCADE
does not have 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.
+
+
To declare a cursor:
- DECLARE liahona CURSOR
- FOR SELECT * FROM films;
+DECLARE liahona CURSOR
+ FOR SELECT * FROM films;
-
-
-
-
-
- <ReturnValue>tablee>
+ <replaceable class="parameter">tablee>
- <ReturnValue>conditione>
+ <replaceable class="parameter">conditione>
-
-
-
+status
If count is 0,
- no rows are deleted.
+ no rows were deleted.
Remove all films but musicals:
- DELETE FROM films WHERE kind <> 'Musical';
+DELETE FROM films WHERE kind <> 'Musical';
- SELECT * FROM films;
+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
+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)
- Clear the table films:
+ Clear the table films:
- DELETE FROM films;
+DELETE FROM films;
- SELECT * FROM films;
- code|title|did|date_prod|kind|len
- ----+-----+---+---------+----+---
- (0 rows)
+SELECT * FROM films;
+code|title|did|date_prod|kind|len
+----+-----+---+---------+----+---
+(0 rows)
SQL92
- SQL92 defines a different syntax for a positioned DELETE statement:
+
SQL92 allows a positioned DELETE statement:
- DELETE FROM table WHERE CURRENT OF cursor
+DELETE FROM table WHERE CURRENT OF cursor
- where cursor identifies an open cursor.
+ where
cursor identifies an open cursor. Interactive cursors in
Postgres are read-only.
+
1998-04-15
- DROP AGGREGATE name type
+DROP AGGREGATE name type
-
-
-
-
-
- <ReturnValue>namee>
+ <replaceable class="parameter">namee>
- <ReturnValue>typee>
+ <replaceable class="parameter">typee>
The type of an existing aggregate function.
- (Refer to PostgreSQL User's Guide chapter 4 for
+ (Refer to the PostgreSQL User's Guide for
further information about data types).
This should become a cross-reference rather than a
hard-coded chapter number
-
-
-
+status
- WARN RemoveAggregate: aggregate 'name' for 'type' does not exist
+ WARN RemoveAggregate: aggregate 'name' for 'type' does not exist
Notes
- The DROP AGGREGATE statement is a PostgreSQL
+ The DROP AGGREGATE statement is a
language extension.
int4:
- DROP AGGREGATE myavg int4;
+DROP AGGREGATE myavg int4;
SQL92
- There is no DROP AGGREGATE statement in SQL92.
+ There is no DROP AGGREGATE statement in
SQL92.
1998-04-15
- DROP DATABASE name
+DROP DATABASE name
-
-
-
-
-
-
-
-
+status
+
+
+ ERROR: destroydb cannot be executed on an open database
+
+
+ This message occurs if the specified database does not exist.
+
+
+
Notes
-
+
+ DROP DATABASE statement is a
Postgres
+ language extension.
+
+
- This query should NOT be executed interactively.
- The destroydb script should be used instead.
+ This query cannot be executed while connected to the target
+database. It is usually preferable to use the
+ destroydb script instead.
-
- Some explanation would be desirable here!
-
- DROP DATABASE statement is a PostgreSQL language extension.
+
+
Refer to the CREATE DATABASE statement for
SQL92
- There is no DROP DATABASE statement in SQL92.
+ There is no
DROP DATABASE in SQL92.
1998-04-15
- DROP FUNCTION name ( [type [, ...]] )
+DROP FUNCTION name ( [ type [, ...] ] )
-
-
-
-
-
-
-
-
+status
-
- WARN RemoveFunction: Function "name" ("types") does not exist
+ WARN RemoveFunction: Function "name" ("types") does not exist
This message is given if the function specified does not
-exist into database.
+exist in the current database.
Notes
- Refer to the
-
- CREATE FUNCTION
+ Refer to
+
+CREATE FUNCTION
+
- statement to create aggregate functions.
+ to create aggregate functions.
This command removes the square root function:
- DROP FUNCTION sqrt(int4);
+DROP FUNCTION sqrt(int4);
Compatibility
-
- >DROP FUNCTION statement is a PostgreSQL language extension.
+
DROP FUNCTION is a Postgres language extension.
SQL/PSM
- The SQL/PSM DROP FUNCTION statement has the following syntax:
+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 }
+DROP [ SPECIFIC ] FUNCTION name { RESTRICT | CASCADE }
1998-04-15
- DROP INDEX index_name
+DROP INDEX index_name
-
-
-
-
-
-
-
-
+status
- This message occurs if "index_name"
+ This message occurs if index_name
is not an index in the database.
Notes
- DROP INDEX is a PostgreSQL language extension.
+
DROP INDEX is a
Postgres
+ language extension.
Refer to the CREATE INDEX statement for
- information on how to create indices.
+ information on how to create indexes.
This command will remove the title_idx index:
- DROP INDEX title_idx;
+DROP INDEX title_idx;
SQL92
-SQL92 defines commands by which to access a generic relational database.
-Indices are an implementation-dependent feature and hence
-there is no DROP INDEX statement in SQL92.
+
SQL92 defines commands by which to access
+ a generic relational database.
+Indexes are an implementation-dependent feature and hence
+there are no index-specific commands or definitions in the
1998-04-15
- DROP PROCEDURAL LANGUAGE 'langname'
+DROP PROCEDURAL LANGUAGE 'langname'
-
-
-
-
-
- eturnValue>langname>
+ EPLACEABLE CLASS="PARAMETER">langname>
-
-
-
+status
DROP PROCEDURAL LANGUAGE will remove the definition
- of the previously registered procedural language with the name
+ of the previously registered procedural language having the name
'langname'.
The DROP PROCEDURAL LANGUAGE statement is
- a PostgreSQL language extension.
+ a
Postgres language extension.
- Refer to the CREATE PROCEDURAL LANGUAGE statement
+ Refer to CREATE PROCEDURAL LANGUAGE
for information on how to create procedural languages.
This command removes the PL/Sample language:
- DROP PROCEDURAL LANGUAGE 'plsample'
+DROP PROCEDURAL LANGUAGE 'plsample'
SQL92
- There is no DROP PROCEDURAL LANGUAGE statement in SQL92.
+ There is no DROP PROCEDURAL LANGUAGE in
- 1998-04-15
+ 1998-09-22
- DROP OPERATOR id ( type | NONE [,...] );
+DROP OPERATOR id ( type | NONE [,...] )
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
- <ReturnValue>ide>
+ <replaceable class="parameter">ide>
- <ReturnValue>typee>
+ <replaceable class="parameter">typee>
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- ERROR: RemoveOperator: ... does not exist
+ ERROR: RemoveOperator: binary operator 'id' taking 'type1' and 'type2' does not exist
+
+
+ This message occurs if the specified binary operator does not exist.
+
+
+
+
+
+ ERROR: RemoveOperator: left unary operator 'id' taking 'type' does not exist
+
+
+ This message occurs if the specified left unary operator
+ specified does not exist.
+
+
+
+
+
+ ERROR: RemoveOperator: right unary operator 'id' taking 'type' does not exist
- This message occurs if the operator specified doesn't exist.
+ This message occurs if the specified right unary operator
+ specified does not exist.
- 1998-04-15
+ 1998-09-22
Description
- 1998-04-15
+ 1998-09-22
Notes
- The DROP OPERATOR statement is a PostgreSQL
+ The DROP OPERATOR statement is a
language extension.
- Refer to the CREATE OPERATOR statement for
+ Refer to CREATE OPERATOR for
information on how to create operators.
- It is the user's responsibility to remove any access methods,
- operator classes, and so on, that rely on the deleted operator.
+ It is the user's responsibility to remove any access methods and
+ operator classes that rely on the deleted operator.
Remove power operator a^n for int4:
- DROP OPERATOR ^ (int4, int4);
+DROP OPERATOR ^ (int4, int4);
Remove left unary operator !a for booleans:
- DROP OPERATOR ! (none, bool);
+DROP OPERATOR ! (none, bool);
Remove right unary factorial operator a! for
int4:
- DROP OPERATOR ! (int4, none);
+DROP OPERATOR ! (int4, none);
- 1998-04-15
+ 1998-09-22
SQL92
- There is no DROP OPERATOR statement in SQL92.
+ There is no
DROP OPERATOR in SQL92.
- 1998-04-15
+ 1998-09-22
- DROP RULE name
+DROP RULE name
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
- <ReturnValue>namee>
+ <replaceable class="parameter">namee>
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- 1998-04-15
+ 1998-09-22
Description
- DROP RULE drops a rule from the specified PostgreSQL rule
- system. PostgreSQL will immediately cease enforcing it and
+ DROP RULE drops a rule from the specified
+ will immediately cease enforcing it and
will purge its definition from the system catalogs.
- 1998-04-15
+ 1998-09-22
Notes
- The DROP RULE statement is a PostgreSQL
+ The DROP RULE statement is a
language extension.
- Refer to the CREATE RULE statement for
+ Refer to CREATE RULE for
information on how to create rules.
- 1998-04-15
+ 1998-09-22
Bugs
- 1998-04-15
+ 1998-09-22
SQL92
- There is no DROP RULE statement in SQL92.
+ There is no DROP RULE in SQL92.
- 1998-04-15
+ 1998-09-22
- DROP SEQUENCE seqname [, ...]
+DROP SEQUENCE seqname [, ...]
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
- eturnValue>seqname>
+ EPLACEABLE CLASS="PARAMETER">seqname>
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- This message occurs if the sequence specified does not exist.
+ This message occurs if the specified sequence does not exist.
- 1998-04-15
+ 1998-09-22
Description
- 1998-04-15
+ 1998-09-22
Notes
- The DROP SEQUENCE statement is a PostgreSQL
+ The DROP SEQUENCE statement is a
language extension.
To remove sequence serial from database:
- DROP SEQUENCE serial
+DROP SEQUENCE serial
- 1998-04-15
+ 1998-09-22
SQL92
- There is no DROP SEQUENCE statement in SQL92.
+ There is no
DROP SEQUENCE in SQL92.
- 1998-04-15
+ 1998-09-22
- DROP TABLE table [, ...]
+DROP TABLE table [, ...]
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- If table/view specified doesn't exist into database.
+ If the specified table or view does not exist in the database.
- 1998-04-15
+ 1998-09-22
Description
- DROP TABLE removes tables and views from the database.
+DROP TABLE removes tables and views from the database.
Only its owner may destroy a table or view. A table
- may be emptied of rows, but not destroyed, by using DELETE.
+ may be emptied of rows, but not destroyed, by using DELETE.
- If a table being destroyed has secondary indices on it,
+ If a table being destroyed has secondary indexes on it,
they will be removed first. The removal of just a
- secondary index will not affect the indexed table.
+ secondary index will not affect the contents of the underlying table.
- 1998-04-15
+ 1998-09-22
Notes
- Refer to the CREATE TABLE and
- ALTER TABLE statements for information on
+ Refer to CREATE TABLE and
+ ALTER TABLE for information on
how to create or modify tables.
distributors tables:
- DROP TABLE films, distributors
+DROP TABLE films, distributors
- 1998-04-15
+ 1998-09-22
SQL92
SQL92 specifies some additional capabilities for DROP TABLE:
- DROP TABLE table { RESTRICT | CASCADE }
+DROP TABLE table { RESTRICT | CASCADE }
At present, to remove a referenced view you must drop
- it by hand.
+ it explicitly.
- 1998-04-15
+ 1998-09-22
- DROP TRIGGER name ON table
+DROP TRIGGER name ON table
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
- eturnValue>name>
+ EPLACEABLE CLASS="PARAMETER">name>
- eturnValue>table>
+ EPLACEABLE CLASS="PARAMETER">table>
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- 1998-04-15
+ 1998-09-22
Description
- 1998-04-15
+ 1998-09-22
Notes
- The DROP TRIGGER statement is a PostgreSQL
+
DROP TRIGGER is a
Postgres
language extension.
- Refer to the CREATE TRIGGER statement for
+ Refer to CREATE TRIGGER for
information on how to create triggers.
Usage
- Destroy the if_dist_exists trigger on table films:
+ Destroy the if_dist_exists trigger
+ on table films:
- DROP TRIGGER if_dist_exists ON films;
+DROP TRIGGER if_dist_exists ON films;
- 1998-04-15
+ 1998-09-22
SQL92
- There is no DROP TRIGGER statement in SQL92.
+ There is no DROP TRIGGER statement in
- 1998-04-15
+ 1998-09-22
- DROP TYPE typename
+DROP TYPE typename
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
- eturnValue>typename>
+ EPLACEABLE CLASS="PARAMETER">typename>
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- 1998-04-15
+ 1998-09-22
Description
- 1998-04-15
+ 1998-09-22
Notes
- DROP TYPE statement is a PostgreSQL language extension.
+ DROP TYPE statement is a
Postgres
+ language extension.
- Refer to the CREATE TYPE statement for
+ Refer to CREATE TYPE for
inforamation on how to create types.
It is the user's responsibility to remove any operators,
- functions, aggregates, access methods, subtypes, classes,
- and so on, that use a deleted type.
+ functions, aggregates, access methods, subtypes, and classes
+ that use a deleted type.
- 1998-04-15
+ 1998-09-22
Bugs
To remove the box type:
- DROP TYPE box
+DROP TYPE box
- 1998-04-15
+ 1998-09-22
SQL3
- DROP TYPE is a SQL3 statement.
+ DROP TYPE is a
SQL3 statement.
- 1998-04-15
+ 1998-09-22
- DROP USER username
+DROP USER username
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
- eturnValue>username>
+ EPLACEABLE CLASS="PARAMETER">username>
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- 1998-04-15
+ 1998-09-22
Description
- The DROP USER statement removes the named
+ DROP USER removes the specified
user from the database,
along with any databases owned by the user. It
does not remove tables, views, or triggers owned by the
named user in databases not owned by the user. This statement
- can be used in the place of the destroyuser>
+ can be used in
place of the destroyuser>
script, regardless of how the user was created.
- 1998-04-15
+ 1998-09-22
Notes
- The DROP USER statement is a PostgreSQL
+
DROP USER is a
Postgres
language extension.
- Refer to the CREATE USER and
- ALTER USER statements for information on
+ Refer to CREATE USER and
+ ALTER USER for information on
how to create or modify user accounts.
To drop a user account:
- DROP USER Jonathan;
+DROP USER Jonathan;
- 1998-04-15
+ 1998-09-22
SQL92
- There is no DROP USER statement in SQL92.
+ There is no
DROP USER in SQL92.
- 1998-04-15
+ 1998-09-22
- DROP VIEW view
+DROP VIEW view
- 1998-04-15
+ 1998-09-22
Inputs
-
-
-
-
-
- eturnValue>view>
+ EPLACEABLE CLASS="PARAMETER">view>
- The name of an existing view to drop.
+ The name of an existing view.
-
-
-
- 1998-04-15
+ 1998-09-22
Outputs
+status
- 1998-04-15
+ 1998-09-22
Description
- 1998-04-15
+ 1998-09-22
Notes
- The PostgreSQL DROP TABLE statement also drops views.
+ DROP TABLE statement also drops views.
- Refer to the CREATE VIEW statement for information on how to create views.
+ Refer to CREATE VIEW
+ for information on how to create views.
This command will remove the view called kinds:
- DROP VIEW kinds
+DROP VIEW kinds;
- 1998-04-15
+ 1998-09-22
SQL92
- SQL92 specifies some additional capabilities for
+
SQL92 specifies some additional capabilities for
DROP VIEW:
- DROP VIEW view {RESTRICT | CASCADE}
+DROP VIEW view { RESTRICT | CASCADE }
+
+
+
+ 1998-09-22
+
+
+ Inputs
+
RESTRICT
+
+
+
+
+ 1998-09-22
+
+
+ Notes
+
- At present, to remove a referenced view from a PostgreSQL database,
- you must drop it by hand.
+ At present, to remove a referenced view from a
+ you must drop it explicitly.