Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TbT4i-0005i9-5e for pgsql-performance@postgresql.org; Thu, 22 Nov 2012 09:28:00 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TbT4e-0005On-VB for pgsql-performance@postgresql.org; Thu, 22 Nov 2012 09:27:59 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id 9EBCE284C9; Thu, 22 Nov 2012 01:27:53 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 9B305B05BD; Thu, 22 Nov 2012 01:27:53 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 6F436C1A7F; Thu, 22 Nov 2012 01:27:53 -0800 (PST) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-2.vmware.com Received: from zcs-prod-ext-mta-2.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-2.vmware.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id zKnKHq1seukA; Thu, 22 Nov 2012 01:27:53 -0800 (PST) Received: from [192.168.1.90] (unknown [10.113.62.14]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA id 51DC7C16B1; Thu, 22 Nov 2012 01:17:16 -0800 (PST) Message-ID: <50ADED9B.7000502@vmware.com> Date: Thu, 22 Nov 2012 11:17:15 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.10) Gecko/20121027 Icedove/10.0.10 MIME-Version: 1.0 To: eildert.groeneveld@fli.bund.de CC: Albe Laurenz , pgsql-performance@postgresql.org Subject: Re: fast read of binary data References: <1352717148.3684.18.camel@eno.tzv.local> <1353570844.30293.8.camel@eno.tzv.local> In-Reply-To: <1353570844.30293.8.camel@eno.tzv.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -7.3 (-------) X-Archive-Number: 201211/252 X-Sequence-Number: 48618 On 22.11.2012 09:54, Eildert Groeneveld wrote: > ok, I did have a look at the libpq librar, and you are right, there is a > way to obtain binary data from the backend through the PQexecParams > > res = PQexecParams(conn, > "DECLARE myportal CURSOR FOR select genotype_bits > from v_genotype_data", > 0, /* zero param */ > NULL, /* let the backend deduce param type */ > paramValues, > NULL, /* don't need param lengths since text*/ > NULL, /* default to all text params */ > 1); /* ask for binary results */ > > genotype_bits is defined as bit varying in the backend. When writing the > results: > for (i = 0; i< PQntuples(res); i++) > { > for (j = 0; j< nFields; j++) > fwrite(PQgetvalue(res, i, j),100000,1,f); > } > > it is clear that the results are NOT in binary format: > eg(eno,snp): od -b junk |head > 0000000 061 060 061 060 061 060 061 060 061 060 061 060 061 060 061 060 You need to ask for binary results when you execute the FETCH statements. Asking for binary results on the DECLARE CURSOR statement has no effect, as DECLARE CURSOR doesn't return any results; it's the FETCH that follows that returns the result set. - Heikki