Re: PQgetvalue failed to return column value for non-text data in binary format - Mailing list pgsql-interfaces

From Andrew McNamara
Subject Re: PQgetvalue failed to return column value for non-text data in binary format
Date
Msg-id 20070521055759.848496006EA@longblack.object-craft.com.au
Whole thread Raw
In response to PQgetvalue failed to return column value for non-text data in binary format  (Jeff Lynn <jmlynn@rogers.com>)
Responses Re: PQgetvalue failed to return column value for non-text data in binary format  (Jeff Lynn <jmlynn@rogers.com>)
List pgsql-interfaces
>I am new to PostgreSQL and tried using the libpq C library.  I can read 
>a test table using PQgetvalue for text format, i.e. format = 0.  
>However, when I experiment with using binary output format, I was unable 
>to read anything else except result set fiend that is in char(x), 
>varchar(x), i.e., character string data.
>
>What have I done wrong?

The data returned in binary mode is in a (largely undocumented)
PostgreSQL form. Types like int4, and float8 are returned in network
byte order [1], while other types such as timestamps are in more subtle
formats. The only canonical reference to these formats is the PostgreSQL
source. 

In general, you should just use the text format, as it's more portable
and less likely to change over time, although the specifics of the text
format are also largely undocumented.

[1] http://en.wikipedia.org/wiki/Endianness

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/


pgsql-interfaces by date:

Previous
From: Jeff Lynn
Date:
Subject: PQgetvalue failed to return column value for non-text data in binary format
Next
From: Jeff Lynn
Date:
Subject: Re: PQgetvalue failed to return column value for non-text data in binary format