amphp / postgres

Async Postgres client for PHP based on Amp.
MIT License
97 stars 20 forks source link

Invalid parsing of Postgres type int2vector #68

Open flavacaster opened 1 day ago

flavacaster commented 1 day ago

PHP: 8.3.0 ext-pgsql: 8.3.0 amphp/postgres: v2.1.0 postgresql version 14.6 (also reproduced on 17.0)

e.g. try to execute this SQL

SELECT      quote_ident(ic.relname) AS relname,
                   i.indisunique,
                   i.indisprimary,
                   i.indkey,
                   i.indrelid,
                   pg_get_expr(indpred, indrelid) AS "where"
              FROM pg_index i
                   JOIN pg_class AS tc ON tc.oid = i.indrelid
                   JOIN pg_namespace tn ON tn.oid = tc.relnamespace
                   JOIN pg_class AS ic ON ic.oid = i.indexrelid
             WHERE ic.oid IN (
                SELECT indexrelid
                FROM pg_index i, pg_class c, pg_namespace n WHERE c.oid = i.indrelid AND c.relnamespace = n.oid AND n.nspname = ANY(current_schemas(false)) AND c.relname = 'doctrine_migration_versions' AND n.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast'))

like this

image

and an exception is thrown "Parse error while splitting array: Missing opening bracket" in /app/vendor/amphp/postgres/src/Internal/ArrayParser.php line 64 when parsing i.indkey (i.indkey has type int2vector, in this case value is returned to php as string "1")

P.S. for a field with type int2vector function pg_field_type_oid() returns OID 22 and pg_field_type( ) returns "int2vector"

I suppose the problem is here \Amp\Postgres\Internal\PgSqlResultIterator::cast

image

I guess int2vector should be treated/parse as a regular string to fix this?

flavacaster commented 1 day ago

Here's how Doctrine DBAL handles mapping

https://github.com/doctrine/dbal/blob/4.2.x/src/Driver/PgSQL/Result.php#L236

flavacaster commented 14 hours ago

@trowski