mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
In ALTER COLUMN TYPE, strip any implicit coercion operations appearing
at the top level of the column's old default expression before adding an implicit coercion to the new column type. This seems to satisfy the principle of least surprise, as per discussion of bug #1290.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.73 2004/07/11 23:13:51 tgl Exp $
|
||||
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_table.sgml,v 1.74 2004/10/22 17:20:04 tgl Exp $
|
||||
PostgreSQL documentation
|
||||
-->
|
||||
|
||||
@ -459,6 +459,22 @@ ALTER TABLE table ALTER COLUMN anycol TYPE anytype;
|
||||
data.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The <literal>USING</literal> option of <literal>ALTER TYPE</> can actually
|
||||
specify any expression involving the old values of the row; that is, it
|
||||
can refer to other columns as well as the one being converted. This allows
|
||||
very general conversions to be done with the <literal>ALTER TYPE</>
|
||||
syntax. Because of this flexibility, the <literal>USING</literal>
|
||||
expression is not applied to the column's default value (if any); the
|
||||
result might not be a constant expression as required for a default.
|
||||
This means that when there is no implicit or assignment cast from old to
|
||||
new type, <literal>ALTER TYPE</> may fail to convert the default even
|
||||
though a <literal>USING</literal> clause is supplied. In such cases,
|
||||
drop the default with <literal>DROP DEFAULT</>, perform the <literal>ALTER
|
||||
TYPE</>, and then use <literal>SET DEFAULT</> to add a suitable new
|
||||
default.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If a table has any descendant tables, it is not permitted to add,
|
||||
rename, or change the type of a column in the parent table without doing
|
||||
|
Reference in New Issue
Block a user