Re: Alter the datatype on all tables present in the database (bigint to varchar)

Adrian Klaver <adrian.klaver@aklaver.com>

From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Gambhir Singh <gambhir.singh05@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Date: 2026-05-14T20:11:45Z
Lists: pgsql-general
On 5/14/26 11:34 AM, Gambhir Singh wrote:

Please reply to list also.
Ccing list

> Hi Adrian,
> 
> I've received this requirement from the application team. My main 
> concern is the partitioned tables.

I would think there would be a least some rationale for doing this, if 
for no other reason then to determine whether this is the best solution.


 From here:

https://www.postgresql.org/docs/17/sql-altertable.html

"Adding a column with a volatile DEFAULT or changing the type of an 
existing column will require the entire table and its indexes to be 
rewritten. As an exception, when changing the type of an existing 
column, if the USING clause does not change the column contents and the 
old type is either binary coercible to the new type or an unconstrained 
domain over the new type, a table rewrite is not needed. However, 
indexes must always be rebuilt unless the system can verify that the new 
index would be logically equivalent to the existing one. For example, if 
the collation for a column has been changed, an index rebuild is always 
required because the new sort order might be different. However, in the 
absence of a collation change, a column can be changed from text to 
varchar (or vice versa) without rebuilding the indexes because these 
data types sort identically. Table and/or index rebuilds may take a 
significant amount of time for a large table; and will temporarily 
require as much as double the disk space."


You also mentioned FKs, do these involve the columns being changed?

> 
> Thanks & Regards
> Gambhir Singh
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com