Re: Increasing a NUMERIC column precision doesn't cause a table rewrite. Why?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marcelo Fernandes <marcefern7(at)gmail(dot)com>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Increasing a NUMERIC column precision doesn't cause a table rewrite. Why?
Date: 2025-11-03 16:31:12
Message-ID: 329227.1762187472@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marcelo Fernandes <marcefern7(at)gmail(dot)com> writes:
> After doing some playing around with different operations against a numeric
> column, namely: increasing/decreasing the precision or increasing/decreasing
> the scale, I noticed that the table is rewritten in all cases except when
> increasing the precision number.

Yup.

> For example, is there a catalog table I can have a look to see how these values
> are defined, along with some form of documentation to understand how they are
> interpreted by Postgres?

You'd have to look into the source code:

https://github.com/postgres/postgres/blob/c4067383cb2c155c4cfea2351036709e2ebb3535/src/backend/utils/adt/numeric.c

The first few hundred lines of numeric.c are largely comments that
you'd find relevant. Also see numeric_support():

https://github.com/postgres/postgres/blob/c4067383cb2c155c4cfea2351036709e2ebb3535/src/backend/utils/adt/numeric.c#L1179

ALTER TABLE skips table rewrite if the datatype conversion expression
is simplified to a no-op by a support function such as
numeric_support.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2025-11-03 16:56:25 Re: Enquiry about TDE with PgSQL
Previous Message Adrian Klaver 2025-11-03 16:20:21 Re: Enquiry about TDE with PgSQL