You already saw my related answer addressing the reverse conversion timestamp
→ timestamptz
without table rewrite:
Well, since Postgres 12 the same "easter egg" feature applies to timestamptz
→ timestamp
as well. The release notesrelease notes:
Allow
ALTER TABLE ... SET DATA TYPE
changing betweentimestamp
andtimestamptz
to avoid a table rewrite when the session time zone is UTC (Noah Misch)In the UTC time zone, these two data types are binary compatible.
So just:
SET timezone = 'UTC'; -- unless already set to UTC
ALTER TABLE tbl ALTER COLUMN ts TYPE timestamp;
RESET timezone; -- optional
And you don't have to mess with system catalogs directly (which should be avoided if at all possible).