Skip site navigation (1) Skip section navigation (2)

Retrieving points, arrays, ... with libpq

From: <Georges(dot)Brefort(at)sanofi-aventis(dot)com>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: Retrieving points, arrays, ... with libpq
Date: 2008-10-20 15:06:25
Message-ID: AC1B5B770E3FD54A94DED61FA96B12C3E06A46@CLPW44.f2.enterprise (view raw or flat)
Thread:
Lists: pgsql-interfaces
Hello,
 
Sorry to eventually bother you with questions coming from a newcomer to
Postgres: I wonder how to retrieve data of such types as Points, enum,
arrays (and all those fancy datatypes that have no directly equivalent
representation in C) using the libpq library.
 
For example, imagine a table like this one, filed with the relevant
information:
 
create type badluck as enum ( 'no more gas', 'flat tire', 'no keys' );
 
create table myTable(
    id SERIAL,
    carStatus badluck,
    whereIsIt Point [,
    and other columns]
);
    
I have read the most recent documentation from the first to the very
last line, and I guess I can retreive data of any type with the
PQgetValue() function,  something like: 
 
char* chunkOfMemory = PQgetvalue( (const PGresult*) myresult,
row_number, column_number);
 
But then, is it possible to cast the char* pointer to some meaningfull C
structure if column_number relates to some datatype other than text or
integer ?
 
For example, with regards to enum values, the documentation states that
the length takes 4 bytes and the label at most NAMEDATALEN bytes, so is
it equivalent to (or laid out as) something like 
struct pgenum {
unsigned char length[4];
char label[NAMEDATALEN];
};
 
(This is only one example, I have not been able to find the layout of
datatypes like Point and Array).
 
Do you know of any document that describe all those data types in term
of the equivalent C structure (if there is any such structure of
course).
 
Thank you again for your help and your patience.
 
Georges Brefort
 

Responses

pgsql-interfaces by date

Next:From: Jeroen VermeulenDate: 2008-10-22 05:27:28
Subject: Re: Retrieving points, arrays, ... with libpq
Previous:From: Jakob LechnerDate: 2008-10-13 15:43:50
Subject: Re: Timestamp with libpq

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group