The current documentation does not mention that the column statistics are removed which I can see they are in src/backend/commands/tablecmds.c
ATExecAlterColumnType /* * Drop any pg_statistic entry for the column, since it's now wrong type */ RemoveStatistics(RelationGetRelid(rel), attnum); Although this might be obvious it tripped me up. For example renaming and SET STATISTICS preserves statistics. Patch attached. Regards, Nikolai
diff --git i/doc/src/sgml/ref/alter_table.sgml w/doc/src/sgml/ref/alter_table.sgml index 8129157..ef59db0 100644 --- i/doc/src/sgml/ref/alter_table.sgml +++ w/doc/src/sgml/ref/alter_table.sgml @@ -187,7 +187,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM This form changes the type of a column of a table. Indexes and simple table constraints involving the column will be automatically converted to use the new column type by reparsing the originally - supplied expression. + supplied expression. Note this will remove the column's statistics + so will normally be followed by an <link linkend="sql-analyze"><command>ANALYZE</command></link> of the table. The optional <literal>COLLATE</literal> clause specifies a collation for the new column; if omitted, the collation is the default for the new column type.
signature.asc
Description: OpenPGP digital signature