Re: Interest in serializing composite types?
[email protected] (Andrew Dunstan) Mon, 25 Aug 2014 14:32:15 -0400
| Newsgroups | perl.dbd.pg |
|---|---|
| Message-ID | <[email protected]> |
On 08/25/2014 01:53 PM, David E. Wheeler wrote: > On Aug 25, 2014, at 10:52 AM, Greg Sabino Mullane <[email protected]> wrote: > >> The biggest problem is that any composite types are going to be user-defined >> types, and thus DBD::Pg cannot know about them in advance (as it does for >> arrays). This problem has reared its head already. We can query the system >> catalogs to gather information about data types, but the key point is when? >> On connection? When we encounter an unknown type? (tricky, as we are already >> inside of an active transaction). Perhaps allow the user to call some method >> that tells us to grab the information? I'm thinking some combination of >> the former and latter will work: allows a connection attribute that says >> "grab information about all user types right after you connect" as well as a >> method that does the same thing (or allows some wildcards, etc.). Once that >> is in place, it should be relatively easy to roll multiple columns into a >> hashref .. I think. Haven't actually dug into that part of the code yet :) > OTOH, would be awesome to have an attribute to serialize and deserialize JSON and JSONB values. :-) > Well, of course, json and jsonb are already serializations. Even jsonb in binary mode is sent to the client as a json string (with a version number in case we ever decide to send/receive a different binary format). And turning a composite into json is pretty simple - in 9.4 it's just to_json(recordval). populate_json(null::recordtype, jsonval) pretty much does the reverse. On the perl side there are well known modules for moving between hashes and json objects. Maybe with some sort of Tie mechanism you could make that almost transparent? cheers andrew