diff options
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/ref/alter_table.sgml | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 4bf449587cc..1c222d63e0b 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -203,10 +203,11 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM <term><literal>SET</literal>/<literal>DROP DEFAULT</literal></term> <listitem> <para> - These forms set or remove the default value for a column. - Default values only apply in subsequent <command>INSERT</command> - or <command>UPDATE</command> commands; they do not cause rows already in the - table to change. + These forms set or remove the default value for a column (where + removal is equivalent to setting the default value to NULL). The new + default value will only apply in subsequent <command>INSERT</command> + or <command>UPDATE</command> commands; it does not cause rows already + in the table to change. </para> </listitem> </varlistentry> @@ -268,6 +269,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM These forms change whether a column is an identity column or change the generation attribute of an existing identity column. See <xref linkend="sql-createtable"/> for details. + Like <literal>SET DEFAULT</literal>, these forms only affect the + behavior of subsequent <command>INSERT</command> + and <command>UPDATE</command> commands; they do not cause rows + already in the table to change. </para> <para> @@ -1370,6 +1375,32 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM <programlisting> ALTER TABLE distributors ADD COLUMN address varchar(30); </programlisting> + That will cause all existing rows in the table to be filled with null + values for the new column. + </para> + + <para> + To add a column with a non-null default: +<programlisting> +ALTER TABLE measurements + ADD COLUMN mtime timestamp with time zone DEFAULT now(); +</programlisting> + Existing rows will be filled with the current time as the value of the + new column, and then new rows will receive the time of their insertion. + </para> + + <para> + To add a column and fill it with a value different from the default to + be used later: +<programlisting> +ALTER TABLE transactions + ADD COLUMN status varchar(30) DEFAULT 'old', + ALTER COLUMN status SET default 'current'; +</programlisting> + Existing rows will be filled with <literal>old</literal>, but then + the default for subsequent commands will be <literal>current</literal>. + The effects are the same as if the two sub-commands had been issued + in separate <command>ALTER TABLE</command> commands. </para> <para> |