arc / dbd-pgpp

Pure-Perl PostgreSQL database driver for DBI
http://search.cpan.org/dist/DBD-PgPP/
4 stars 3 forks source link

DBD::PgPP returns arrays as strings #2

Open FGasper opened 10 years ago

FGasper commented 10 years ago

$dbh->selectrow_array(q{SELECT ARRAY['haha','h,"h']});

… is returning a Perl string for me rather than an array.

Is this a known bug?

FGasper commented 10 years ago

Just to clarify, the following comes from a Perl test:

diag explain $dbh->selectall_arrayref(q{SELECT ARRAY['haha','h,"h']});

… and it gives:

# [
#   [
#     '{haha,"h,\\"h"}'
#   ]
# ]
arc commented 10 years ago

Hi there. I’d definitely go with “there’s currently no special support for values of Postgres array types”, but it’s up to you whether you call that a bug or simply a nonexistent feature. :-)

If you’re interested in adding such array support, the starting point at the DBD::PgPP side of things is probably https://github.com/arc/dbd-pgpp/blob/master/lib/DBD/PgPP.pm#L1349

You’ll also need to deal with finding which OIDs correspond to array types. That information could be looked up in the pg_type table in the system catalog, but that’s probably not something to be done on every query (or even every connection). Instead I’d suggest statically generating the list of type OIDs from a copy of the Postgres sources, and shipping the generated data as part of DBD::PgPP; that’s roughly what the Perl script embedded in the types.c file from DBD::Pg does. Doing that would also allow replacing the hard-coded OIDs 16 (for bool) and 17 (for bytea) round line 1349.