mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Cause ALTER TABLE to perform ALTER COLUMN DROP DEFAULT operations during
the DROP pass rather than the ADD_CONSTR pass. On examining the code I think this was just an oversight rather than intentional, and it seems to satisfy the principle of least surprise better than the alternative solution that was discussed. Add an example to the ref page showing how to do ALTER TYPE and update the default in one command. Per gripe from Markus Bertheau that that wasn't possible.
This commit is contained in:
parent
89c07b18a6
commit
7946f77220
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.87 2006/07/04 18:07:24 tgl Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.88 2006/08/03 20:57:06 tgl Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -741,6 +741,19 @@ ALTER TABLE foo
|
|||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
The same, when the column has a default expression that won't automatically
|
||||||
|
cast to the new datatype:
|
||||||
|
<programlisting>
|
||||||
|
ALTER TABLE foo
|
||||||
|
ALTER COLUMN foo_timestamp DROP DEFAULT,
|
||||||
|
ALTER COLUMN foo_timestamp TYPE timestamp with time zone
|
||||||
|
USING
|
||||||
|
timestamp with time zone 'epoch' + foo_timestamp * interval '1 second',
|
||||||
|
ALTER COLUMN foo_timestamp SET DEFAULT now();
|
||||||
|
</programlisting>
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To rename an existing column:
|
To rename an existing column:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.198 2006/07/31 20:09:00 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.199 2006/08/03 20:57:06 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2000,7 +2000,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd,
|
|||||||
ATSimplePermissions(rel, true);
|
ATSimplePermissions(rel, true);
|
||||||
ATSimpleRecursion(wqueue, rel, cmd, recurse);
|
ATSimpleRecursion(wqueue, rel, cmd, recurse);
|
||||||
/* No command-specific prep needed */
|
/* No command-specific prep needed */
|
||||||
pass = AT_PASS_ADD_CONSTR;
|
pass = cmd->def ? AT_PASS_ADD_CONSTR : AT_PASS_DROP;
|
||||||
break;
|
break;
|
||||||
case AT_DropNotNull: /* ALTER COLUMN DROP NOT NULL */
|
case AT_DropNotNull: /* ALTER COLUMN DROP NOT NULL */
|
||||||
ATSimplePermissions(rel, false);
|
ATSimplePermissions(rel, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user