Accessing composite type elements - Mailing list pgsql-general

From Garfield Lewis
Subject Accessing composite type elements
Date
Msg-id VI1PR0502MB398150C23E5450CCC30BE666E3DE9@VI1PR0502MB3981.eurprd05.prod.outlook.com
Whole thread Raw
Responses Re: Accessing composite type elements
List 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

pgsql-general by date:

Previous
From: Danny Shemesh
Date:
Subject: Re: Extended multivariate statistics are ignored (potentially related to high null fraction, not sure)
Next
From: Tom Lane
Date:
Subject: Re: Accessing composite type elements