Re: Avoid some table rewrites for ALTER TABLE .. SET DATA TYPE array coerce - Mailing list pgsql-hackers

From Matthias van de Meent
Subject Re: Avoid some table rewrites for ALTER TABLE .. SET DATA TYPE array coerce
Date
Msg-id CAEze2Wi4M1grsR0q27etuB-jncJ6qN-1FMdRX-2PkQxcFpM3sQ@mail.gmail.com
Whole thread Raw
In response to Avoid some table rewrites for ALTER TABLE .. SET DATA TYPE array coerce  (jian he <jian.universality@gmail.com>)
List pgsql-hackers
On Wed, 18 Mar 2026 at 12:06, jian he <jian.universality@gmail.com> wrote:
>
> Hi.
>
> Context: https://git.postgresql.org/cgit/postgresql.git/commit/?id=3c5926301aea476025f118159688a6a88b2738bc
> Also see build_coercion_expression, COERCION_PATH_ARRAYCOERCE handling.
>
> It's doable to skip a table rewrite when changing a column's data type from
> one array type to another. We just need some logic to handle
> ArrayCoerceExpr within ATColumnChangeRequiresRewrite.

Are you sure about that?

IIRC, arrays store the element data type's OID on disk (^1), and if we
move from arrays of type X to arrays of type Y then that should also
change the array's on-disk OID: Generic array functions like array_out
rely on the array's type oid to select the lower-level functions to
call into when recursing; and would get the wrong type information if
we don't update this.
This could cause visible differences in output when you change the
time zone of your database after changing the column type from e.g.
timestamptz[] to timestamp[], or enum[] to oid[] if we ever implement
a binary coercible cast from enum to oid (or int, but oid seems more
appropriate).


Kind regards,

Matthias van de Meent
Databricks (https://www.databricks.com)

(^1): Possibly DOMAIN-typed arrays only store the base type, in which
case this would work in the restricted case of coercing to
domain-typed arrays, but I don't think the general case of
binary-coercible types is allowable.



pgsql-hackers by date:

Previous
From: Amul Sul
Date:
Subject: Re: pg_waldump: support decoding of WAL inside tarfile
Next
From: Henson Choi
Date:
Subject: Re: SQL Property Graph Queries (SQL/PGQ)