Skip to content

Fix PostgresAdapter support for ARRAY and custom enum array columns - #2423

Open
JulienChavee wants to merge 1 commit into
cakephp:0.xfrom
JulienChavee:master
Open

Fix PostgresAdapter support for ARRAY and custom enum array columns#2423
JulienChavee wants to merge 1 commit into
cakephp:0.xfrom
JulienChavee:master

Conversation

@JulienChavee

@JulienChavee JulienChavee commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Fix PostgresAdapter support for ARRAY columns

Summary

PostgresAdapter::getColumns() throws when introspecting PostgreSQL array columns:

Phinx\Db\Adapter\UnsupportedColumnTypeException: Column type `ARRAY` is not supported by Postgresql.

PostgreSQL's information_schema.columns reports array columns as data_type = 'ARRAY', with the element type in udt_name (e.g. _int4, _text, _bpchar). Phinx already supported creating array columns (integer[], text[], …) but could not read them back.

A related failure occurred for arrays of custom/user-defined types (e.g. enums):

Phinx\Db\Adapter\UnsupportedColumnTypeException: Column type `my_status_enum[]` is not supported by Postgresql.

isArrayType() previously required a known Phinx base type and only allowed [a-z]+, so identifiers with underscores were rejected.

Changes

  • Resolve ARRAY columns in getColumns() via udt_name and pg_attribute.attndims
  • Accept arrays of native/custom PostgreSQL types (enums, domains, etc.) in isArrayType / getSqlType
  • Translate known Phinx array base types through getSqlType (string[]character varying[]); pass custom types through unchanged
  • Map common PostgreSQL internal aliases in getPhinxType used by array udt_name values:
    • int2smallinteger
    • float8double
    • bpcharchar
  • Extract array handling into parseArrayType(), getArraySqlType(), and getPhinxArrayType()

Example

SELECT column_name, data_type, udt_name
FROM information_schema.columns
WHERE table_name = 'my_table' AND data_type = 'ARRAY';
column_name data_type udt_name
tags ARRAY _varchar
scores ARRAY _int4
statuses ARRAY _my_status_enum

After this change, getColumns() maps those to string[], integer[], and my_status_enum[] respectively.

Test plan

  • getColumns() round-trip for Phinx-created array types (text[], integer[], multi-dimensional json[][], …)
  • Native SQL array columns (varchar[], integer[][])
  • Custom enum array columns (custom_status_enum[]), including changeColumn round-trip
  • Internal udt_name aliases (_int2, _float8, _bpchar, …)
  • getSqlType() translation of Phinx array base types (string[]character varying[], etc.)
  • Full PostgresAdapterTest suite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant