Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit31d2efa

Browse files
committed
Reclassify DEFAULT as a column_constraint item in the CREATE TABLE syntax.
This is how it was documented originally, but several years ago somebodydecided that DEFAULT isn't a type of constraint. Well, the grammar thinksit is. The documentation was wrong in two ways: it alleged that DEFAULThad to appear before any other kind of constraint, and it alleged that youcan't prefix a DEFAULT clause with a "CONSTRAINT name" clause, when in factyou can. (The latter behavior probably isn't SQL-standard, but our grammarhas always allowed it.)This patch responds to Fujii Masao's observation that the ALTER TABLEdocumentation mistakenly implied that you couldn't include DEFAULT inALTER TABLE ADD COLUMN; though this isn't the way he proposed fixing it.
1 parenta5f9640 commit31d2efa

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

‎doc/src/sgml/ref/alter_table.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ALTER TABLE <replaceable class="PARAMETER">name</replaceable>
3232

3333
<phrase>where <replaceable class="PARAMETER">action</replaceable> is one of:</phrase>
3434

35-
ADD [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> <replaceable class="PARAMETER">type</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
35+
ADD [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
3636
DROP [ COLUMN ] [ IF EXISTS ] <replaceable class="PARAMETER">column</replaceable> [ RESTRICT | CASCADE ]
3737
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> [ SET DATA ] TYPE <replaceable class="PARAMETER">type</replaceable> [ USING <replaceable class="PARAMETER">expression</replaceable> ]
3838
ALTER [ COLUMN ] <replaceable class="PARAMETER">column</replaceable> SET DEFAULT <replaceable class="PARAMETER">expression</replaceable>

‎doc/src/sgml/ref/create_table.sgml

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PostgreSQL documentation
2222
<refsynopsisdiv>
2323
<synopsis>
2424
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable> ( [
25-
{ <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [DEFAULT <replaceable>default_expr</replaceable> ] [<replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
25+
{ <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
2626
| <replaceable>table_constraint</replaceable>
2727
| LIKE <replaceable>parent_table</replaceable> [ <replaceable>like_option</replaceable> ... ] }
2828
[, ... ]
@@ -34,7 +34,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <repl
3434

3535
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable>
3636
OF <replaceable class="PARAMETER">type_name</replaceable> [ (
37-
{ <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [DEFAULT <replaceable>default_expr</replaceable> ] [<replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
37+
{ <replaceable class="PARAMETER">column_name</replaceable> WITH OPTIONS [ <replaceable class="PARAMETER">column_constraint</replaceable> [ ... ] ]
3838
| <replaceable>table_constraint</replaceable> }
3939
[, ... ]
4040
) ]
@@ -48,6 +48,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <repl
4848
{ NOT NULL |
4949
NULL |
5050
CHECK ( <replaceable class="PARAMETER">expression</replaceable> ) |
51+
DEFAULT <replaceable>default_expr</replaceable> |
5152
UNIQUE <replaceable class="PARAMETER">index_parameters</replaceable> |
5253
PRIMARY KEY <replaceable class="PARAMETER">index_parameters</replaceable> |
5354
REFERENCES <replaceable class="PARAMETER">reftable</replaceable> [ ( <replaceable class="PARAMETER">refcolumn</replaceable> ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
@@ -226,27 +227,6 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <repl
226227
</listitem>
227228
</varlistentry>
228229

229-
<varlistentry>
230-
<term><literal>DEFAULT
231-
<replaceable>default_expr</replaceable></literal></term>
232-
<listitem>
233-
<para>
234-
The <literal>DEFAULT</> clause assigns a default data value for
235-
the column whose column definition it appears within. The value
236-
is any variable-free expression (subqueries and cross-references
237-
to other columns in the current table are not allowed). The
238-
data type of the default expression must match the data type of the
239-
column.
240-
</para>
241-
242-
<para>
243-
The default expression will be used in any insert operation that
244-
does not specify a value for the column. If there is no default
245-
for a column, then the default is null.
246-
</para>
247-
</listitem>
248-
</varlistentry>
249-
250230
<varlistentry>
251231
<term><literal>INHERITS ( <replaceable>parent_table</replaceable> [, ... ] )</literal></term>
252232
<listitem>
@@ -421,6 +401,27 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE [ IF NOT EXISTS ] <repl
421401
</listitem>
422402
</varlistentry>
423403

404+
<varlistentry>
405+
<term><literal>DEFAULT
406+
<replaceable>default_expr</replaceable></literal></term>
407+
<listitem>
408+
<para>
409+
The <literal>DEFAULT</> clause assigns a default data value for
410+
the column whose column definition it appears within. The value
411+
is any variable-free expression (subqueries and cross-references
412+
to other columns in the current table are not allowed). The
413+
data type of the default expression must match the data type of the
414+
column.
415+
</para>
416+
417+
<para>
418+
The default expression will be used in any insert operation that
419+
does not specify a value for the column. If there is no default
420+
for a column, then the default is null.
421+
</para>
422+
</listitem>
423+
</varlistentry>
424+
424425
<varlistentry>
425426
<term><literal>UNIQUE</> (column constraint)</term>
426427
<term><literal>UNIQUE ( <replaceable class="PARAMETER">column_name</replaceable> [, ... ] )</> (table constraint)</term>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp