On Mon, May 11, 2015 at 02:22:49PM -0400, Greg Sabino Mullane wrote:
> On Thu, May 07, 2015 at 10:04:47PM +0200, Adam Sjøgren wrote:
> > I just thought that when DBD::Pg handles "simple" arrays, handling
> > arrays of tuples wouldn't be much further a step.
> 
> The problem isn't so much as *how* to do it as *when*. It cannot be done 
> when we are reading in a resultset and come across an unknown type. It 
> cannot be done at startup as the overhead of scanning the system tables 
> for custom types would be too heavy. So it would need to be an invoked 
> method. Then it would somehow need to be tied into the current type system. 
> Right now, DBD::Pg uses the Postgres source code to generate a static 
> list of core data types, and knows which ones represent arrays. There is 
> no easy way to shoehorn new entries in there after the fact, so it's not 
> a trivial undertaking. It may be easier/more feasible to set an attribute 
> and tell DBD::Pg directly that column X needs to be handled as an array, 
> but that gets messy in other ways.
> 
> If anyone wants to discuss the design further (and I do want to get this 
> functionality written sometime soon), let's talk on the dbd-pg list only.

I think I'd like to see something along these lines:

    $dbh->{pg_type_mumble} = { $pg_type_id => $pg_type_info, ... };

Where $pg_type_info contains whatever information DBD::Pg needs to handle
that data type.

Then it's no longer DBD::Pg's responsibility to get that information
on-demand. The application would have the responsibility to provide that
info for the types it needs to handle. I'd expect one or more modules to
be developed to gather that info. The info could be cached by the app,
if appropriate, to avoid refetching on each db connection.

Obviously we'd need to discuss what form that information might take.
The slowest but most flexible option would be to simply provide hooks:

    $dbh->{pg_type_mumble} = {
        12345 => {
            perl_to_pg => sub { ... },
            pg_to_perl => sub { ... },
        },
        ...
    };

which would be a handy fallback anyway.

Some other ideas:

    12345 => 54321, # treat type 12345 like type 54321

    pg_to_perl => $PG_TYPE_TREAT_AS_ARRAY, # DBD::Pg exported constant


I wouldn't expect this to do much as it would be implicit:

    $sth->bind_col(1, \$foo, { pg_type => $pg_type_id });

but this might be handy to trigger appropriate serialization to postgres:

    $sth->bind_param(1, $foo, { pg_type => $pg_type_id });

Tim.

p.s. I'm not really familar with this part of DBD::Pg or the type
mechanism in libpq etc so I may be talking nonsense here :)

Reply via email to