Alter timestamp without timezone to with timezone rewrites rows - Mailing list pgsql-hackers

From Dorian Hoxha
Subject Alter timestamp without timezone to with timezone rewrites rows
Date
Msg-id CANsFX06xN-vPYxM+YXyfLezK9twjtK3dFJcOHoubTXng40muoQ@mail.gmail.com
Whole thread Raw
Responses Re: Alter timestamp without timezone to with timezone rewrites rows  (Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>)
List pgsql-hackers
Hi team,

I have a table with a column of "timestamp without timezone" and I want to alter it to a column of "timestamp with timezone" without rewriting the rows.

Looking at the docs, and doing some quick tests, the data-on-disk is identical for both columns. But when doing an alter table, looks like it's rewriting the rows: (PostgreSQL 13.1)

guru=# create table tt(m timestamp without time zone default now());
guru=# insert into tt(m) values(now());
guru=# SELECT xmin, xmax, cmin, cmax, m from tt;
 xmin | xmax | cmin | cmax |             m              
------+------+------+------+----------------------------
  695 |    0 |    0 |    0 | 2021-01-13 11:47:59.146952
(1 row)

guru=# alter table tt alter column m type timestamp with time zone;
guru=# SELECT xmin, xmax, cmin, cmax, m from tt;
 xmin | xmax | cmin | cmax |               m              
------+------+------+------+-------------------------------
  696 |    0 |    4 |    4 | 2021-01-13 11:47:59.146952+01
(1 row)

Is there any reason to rewrite the rows or is it just an optimization that no one hasn't sent a patch ?

Regards,
Dorian

pgsql-hackers by date:

Previous
From: "Daniel Westermann (DWE)"
Date:
Subject: src/tutorial/funcs.source: Wrong comment?
Next
From: Dmitry Dolgov
Date:
Subject: Re: [PATCH] Identify LWLocks in tracepoints