pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Retrieving points, arrays, ... with libpq
2+ messages / 2 participants
[nested] [flat]

* Retrieving points, arrays, ... with libpq
@ 2008-10-20 15:06 Georges.Brefort@sanofi-aventis.com
  2008-10-22 05:27 ` Re: Retrieving points, arrays, ... with libpq Jeroen Vermeulen <jtv@xs4all.nl>
  0 siblings, 1 reply; 2+ messages in thread

From: Georges.Brefort@sanofi-aventis.com @ 2008-10-20 15:06 UTC (permalink / raw)
  To: 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
 

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Retrieving points, arrays, ... with libpq
  2008-10-20 15:06 Retrieving points, arrays, ... with libpq Georges.Brefort@sanofi-aventis.com
@ 2008-10-22 05:27 ` Jeroen Vermeulen <jtv@xs4all.nl>
  0 siblings, 0 replies; 2+ messages in thread

From: Jeroen Vermeulen @ 2008-10-22 05:27 UTC (permalink / raw)
  To: Georges.Brefort@sanofi-aventis.com; +Cc: pgsql-interfaces

Georges.Brefort@sanofi-aventis.com wrote:

> 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 ?

By default, you get your data in a textual representation.  So you need 
to parse the string that that char* points to.  (It's also possible to 
work in binary mode, but then you've got a lot more worries about 
portability and such for not much gain in speed.)


Jeroen



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2008-10-22 05:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-10-20 15:06 Retrieving points, arrays, ... with libpq Georges.Brefort@sanofi-aventis.com
2008-10-22 05:27 ` Jeroen Vermeulen <jtv@xs4all.nl>

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