| From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
|---|---|
| To: | Mauricio Martini <martini(dot)mauricio(at)hotmail(dot)com>, "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Technical validation on altering atttypmod for numeric column in PostgreSQL |
| Date: | 2026-03-23 13:55:40 |
| Message-ID: | 24bc88e97f83e7d0cca8b51c5689daccf01cefa1.camel@cybertec.at |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-admin |
On Mon, 2026-03-23 at 13:02 +0000, Mauricio Martini wrote:
> I am evaluating an approach to change the scale of a numeric column from numeric(18,2)
> to numeric(18,4) in a large table, aiming to avoid the cost of a full table rewrite.
>
> The proposed approach involves directly updating the PostgreSQL system catalog:
>
> UPDATE pg_attribute SET atttypmod = (18 << 16 | 4) + 4 WHERE attrelid = 'table'::regclass
> AND attname = 'column';
>
> Before considering this in practice, I would like to validate a few points:
> * Is this approach considered safe from a data integrity perspective?
> * Is there a risk of inconsistencies in the internal representation of the numeric
> type (especially regarding scale)?
> * Could this impact indexes, functions, or aggregation operations?
> * Is there any official recommendation or prior experience using this approach in
> production environments?
> * Are there additional risks related to rollback, maintenance, or future operations
> (e.g., dump/restore, upgrades)?
>
> The goal is to determine whether this alternative is viable, or if we should stick with more
> standard approaches (e.g., shadow column, incremental migration, etc.).
> If anyone has experience with a similar scenario, your insights would be appreciated.
It should be safe to perform this catalog modification, but I won't take any
liability. "If it breaks, you get to keep both pieces."
Two things come to my mind when considering such a dangerous activity:
- LOCK the table in ACCESS EXCLUSIVE node while you perform the operation
- make sure there is no view that depends on the column, or if there is,
drop the view first and re-create it afterwards
I myself would be a tad afraid to perform something like that. Test well.
Yours,
Laurenz Albe
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Laurenz Albe | 2026-03-23 13:57:37 | Re: Technical validation on altering atttypmod for numeric column in PostgreSQL |
| Previous Message | Holger Jakobs | 2026-03-23 13:47:52 | Re: Technical validation on altering atttypmod for numeric column in PostgreSQL |