From 31d2efaef507f280f4df895e1730a9ec8c31aa12 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 28 Dec 2010 21:38:05 -0500 Subject: [PATCH] Reclassify DEFAULT as a column_constraint item in the CREATE TABLE syntax. This is how it was documented originally, but several years ago somebody decided that DEFAULT isn't a type of constraint. Well, the grammar thinks it is. The documentation was wrong in two ways: it alleged that DEFAULT had to appear before any other kind of constraint, and it alleged that you can't prefix a DEFAULT clause with a "CONSTRAINT name" clause, when in fact you can. (The latter behavior probably isn't SQL-standard, but our grammar has always allowed it.) This patch responds to Fujii Masao's observation that the ALTER TABLE documentation mistakenly implied that you couldn't include DEFAULT in ALTER TABLE ADD COLUMN; though this isn't the way he proposed fixing it. --- doc/src/sgml/ref/alter_table.sgml | 2 +- doc/src/sgml/ref/create_table.sgml | 47 +++++++++++++++--------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 784feaef54..17a1d34d08 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -32,7 +32,7 @@ ALTER TABLE name where action is one of: - ADD [ COLUMN ] column type [ column_constraint [ ... ] ] + ADD [ COLUMN ] column data_type [ column_constraint [ ... ] ] DROP [ COLUMN ] [ IF EXISTS ] column [ RESTRICT | CASCADE ] ALTER [ COLUMN ] column [ SET DATA ] TYPE type [ USING expression ] ALTER [ COLUMN ] column SET DEFAULT expression diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index 8635e80faf..bc5dff0329 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -22,7 +22,7 @@ PostgreSQL documentation CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] table_name ( [ - { column_name data_type [ DEFAULT default_expr ] [ column_constraint [ ... ] ] + { column_name data_type [ column_constraint [ ... ] ] | table_constraint | LIKE parent_table [ like_option ... ] } [, ... ] @@ -34,7 +34,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] table_name OF type_name [ ( - { column_name WITH OPTIONS [ DEFAULT default_expr ] [ column_constraint [ ... ] ] + { column_name WITH OPTIONS [ column_constraint [ ... ] ] | table_constraint } [, ... ] ) ] @@ -48,6 +48,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] expression ) | + DEFAULT default_expr | UNIQUE index_parameters | PRIMARY KEY index_parameters | REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] @@ -226,27 +227,6 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] - - DEFAULT - default_expr - - - The DEFAULT clause assigns a default data value for - the column whose column definition it appears within. The value - is any variable-free expression (subqueries and cross-references - to other columns in the current table are not allowed). The - data type of the default expression must match the data type of the - column. - - - - The default expression will be used in any insert operation that - does not specify a value for the column. If there is no default - for a column, then the default is null. - - - - INHERITS ( parent_table [, ... ] ) @@ -421,6 +401,27 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] + + DEFAULT + default_expr + + + The DEFAULT clause assigns a default data value for + the column whose column definition it appears within. The value + is any variable-free expression (subqueries and cross-references + to other columns in the current table are not allowed). The + data type of the default expression must match the data type of the + column. + + + + The default expression will be used in any insert operation that + does not specify a value for the column. If there is no default + for a column, then the default is null. + + + + UNIQUE (column constraint) UNIQUE ( column_name [, ... ] ) (table constraint) -- 2.40.0