ALTER TABLE ... SET DATA TYPE removes statistics

nikolai.berkoff <nikolai.berkoff@pm.me>

From: "nikolai.berkoff" <nikolai.berkoff@pm.me>
To: "pgsql-docs@lists.postgresql.org" <pgsql-docs@lists.postgresql.org>
Date: 2021-10-08T09:03:34Z
Lists: pgsql-docs

Attachments

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

Commits

  1. Document that ALTER TABLE .. TYPE removes statistics