pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedAccessing composite type elements
5+ messages / 3 participants
[nested] [flat]
* Accessing composite type elements
@ 2022-06-02 15:20 Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 16:23 ` Re: Accessing composite type elements Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 5+ messages in thread
From: Garfield Lewis @ 2022-06-02 15:20 UTC (permalink / raw)
To: pgsql-general
Hi All,
I’m not sure if this is the actual place for this but I guess I can start here. The question I have is, I’ve created a composite type like this:
CREATE TYPE myxml AS { encoding_ int4, xml_ xml };
In my client-side C code I am using PQgetvalue to pull in the data from the row/column. However, since it is a composite type, it is unclear to me how to get the individual members from the data. I have googled but I probably just am not googling the correct term because I cannot find any examples of this being done anywhere. A hex dump of the data gives me this:
0x0000000200000017000000046f0100000000008e000001433c637573746f6d6572696e666f20786d6c6e733d22687474703a2f2f6c7a6c6162732e637573742e636f6d22204369643d22543130303130303031223e3c6e616d653e5461626c6520584d4c…
I can tell that the green portion is my endcoding_ value and the blue section is the xml_ data.
My best guess right now is:
* 0x2 is the number of members
* 0x4 and 0x143 are the lengths of the individual members
* 0x17 and 0x8e are the OID for the member type
Is this the proper layout of these composite types? Can I go ahead and use this without possibly having it broken in the future? Are there any existing supported APIs that I can use instead to get this information?
Regards
G
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Accessing composite type elements
2022-06-02 15:20 Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
@ 2022-06-02 16:23 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-06-02 17:05 ` Re: [EXT] Re: Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2022-06-02 16:23 UTC (permalink / raw)
To: Garfield Lewis <garfield.lewis@lzlabs.com>; +Cc: pgsql-general
Garfield Lewis <garfield.lewis@lzlabs.com> writes:
> In my client-side C code I am using PQgetvalue to pull in the data from the row/column. However, since it is a composite type, it is unclear to me how to get the individual members from the data.
Binary representations are not too well documented :-(. However,
looking at record_send() helps here.
> My best guess right now is:
> * 0x2 is the number of members
> * 0x4 and 0x143 are the lengths of the individual members
> * 0x17 and 0x8e are the OID for the member type
Right, with the additional proviso that -1 "length" indicates a null
field value.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [EXT] Re: Accessing composite type elements
2022-06-02 15:20 Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 16:23 ` Re: Accessing composite type elements Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-06-02 17:05 ` Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 23:00 ` Re: [EXT] Re: Accessing composite type elements Merlin Moncure <mmoncure@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Garfield Lewis @ 2022-06-02 17:05 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general
> Binary representations are not too well documented :-(. However,
> looking at record_send() helps here.
will have a look…
> Right, with the additional proviso that -1 "length" indicates a null
> field value.
Thx, Tom… never thought the null field…
--
Regards,
Garfield A. Lewis
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [EXT] Re: Accessing composite type elements
2022-06-02 15:20 Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 16:23 ` Re: Accessing composite type elements Tom Lane <tgl@sss.pgh.pa.us>
2022-06-02 17:05 ` Re: [EXT] Re: Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
@ 2022-06-02 23:00 ` Merlin Moncure <mmoncure@gmail.com>
2022-06-06 15:22 ` Re: [EXT] Re: Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
0 siblings, 1 reply; 5+ messages in thread
From: Merlin Moncure @ 2022-06-02 23:00 UTC (permalink / raw)
To: Garfield Lewis <garfield.lewis@lzlabs.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
On Thu, Jun 2, 2022 at 12:05 PM Garfield Lewis <garfield.lewis@lzlabs.com>
wrote:
> > Binary representations are not too well documented :-(. However,
> > looking at record_send() helps here.
>
> will have a look…
>
>
> > Right, with the additional proviso that -1 "length" indicates a null
> > field value.
>
> Thx, Tom… never thought the null field…
>
take a look at libpqtypes. it's client side extension library to libpq that
implements the binary protocol.
https://github.com/pgagarinov/libpqtypes
merlin
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: [EXT] Re: Accessing composite type elements
2022-06-02 15:20 Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 16:23 ` Re: Accessing composite type elements Tom Lane <tgl@sss.pgh.pa.us>
2022-06-02 17:05 ` Re: [EXT] Re: Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 23:00 ` Re: [EXT] Re: Accessing composite type elements Merlin Moncure <mmoncure@gmail.com>
@ 2022-06-06 15:22 ` Garfield Lewis <garfield.lewis@lzlabs.com>
0 siblings, 0 replies; 5+ messages in thread
From: Garfield Lewis @ 2022-06-06 15:22 UTC (permalink / raw)
To: Merlin Moncure <mmoncure@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
> take a look at libpqtypes. it's client side extension library to libpq that implements the binary protocol.
>
> https://github.com/pgagarinov/libpqtypes
>
> merlin
Thx, Merlin… I’ll have a look see…
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2022-06-06 15:22 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 15:20 Accessing composite type elements Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 16:23 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-06-02 17:05 ` Garfield Lewis <garfield.lewis@lzlabs.com>
2022-06-02 23:00 ` Merlin Moncure <mmoncure@gmail.com>
2022-06-06 15:22 ` Garfield Lewis <garfield.lewis@lzlabs.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox