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

From: Andrew McNamara <andrewm(at)object-craft(dot)com(dot)au>
To: Jeff Lynn <jmlynn(at)rogers(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQgetvalue failed to return column value for non-text data in binary format
Date: 2007-05-21 05:57:59
Message-ID: 20070521055759.848496006EA@longblack.object-craft.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Jeff Lynn 2007-05-21 21:46:37 Re: PQgetvalue failed to return column value for non-text data in binary format
Previous Message Jeff Lynn 2007-05-21 04:34:51 PQgetvalue failed to return column value for non-text data in binary format