Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 62C3E9FB6F7 for ; Mon, 21 May 2007 02:58:09 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 62457-04 for ; Mon, 21 May 2007 02:58:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id D6A5D9FB2D1 for ; Mon, 21 May 2007 02:58:04 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from syd.object-craft.com.au (ppp167-236-184.static.internode.on.net [59.167.236.184]) by svr4.postgresql.org (Postfix) with ESMTP id C5C115AF03A for ; Mon, 21 May 2007 05:58:03 +0000 (GMT) Received: by longblack.object-craft.com.au (Postfix, from userid 1000) id 848496006EA; Mon, 21 May 2007 15:57:58 +1000 (EST) Received: from longblack (localhost [127.0.0.1]) by longblack.object-craft.com.au (Postfix) with ESMTP id 69EE26006E9; Mon, 21 May 2007 15:57:59 +1000 (EST) To: Jeff Lynn Cc: pgsql-interfaces@postgresql.org Subject: Re: PQgetvalue failed to return column value for non-text data in binary format In-reply-to: <4651216B.2060707@rogers.com> References: <4651216B.2060707@rogers.com> Comments: In-reply-to Jeff Lynn message dated "Mon, 21 May 2007 00:34:51 -0400." Date: Mon, 21 May 2007 15:57:59 +1000 From: Andrew McNamara Message-Id: <20070521055759.848496006EA@longblack.object-craft.com.au> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/38 X-Sequence-Number: 6545 >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/