Re: fast read of binary data - Mailing list pgsql-performance

From Heikki Linnakangas
Subject Re: fast read of binary data
Date
Msg-id 50ADED9B.7000502@vmware.com
Whole thread Raw
In response to Re: fast read of binary data  (Eildert Groeneveld <eildert.groeneveld@fli.bund.de>)
List pgsql-performance
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


pgsql-performance by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Hints (was Poor performance using CTE)
Next
From: Craig Ringer
Date:
Subject: Re: PQconnectStart/PQconnectPoll