Re: libpq - lack of support to set the fetch size - Mailing list pgsql-general

From Daniel Verite
Subject Re: libpq - lack of support to set the fetch size
Date
Msg-id 5699fc18-f65e-43b2-b73e-6c72ef2d7b3d@mm
Whole thread Raw
In response to Re: libpq - lack of support to set the fetch size  (matshyeq <matshyeq@gmail.com>)
Responses Re: libpq - lack of support to set the fetch size  (matshyeq <matshyeq@gmail.com>)
List pgsql-general
    matshyeq wrote:

> The only solution is CURSOR based which I find an awkward low level hack
> comparing to elegant option supported by native library.

That's not the only solution, even with the current DBD::Pg
you could do:

$dbh->do("COPY (sql-squery) TO STDOUT");
my $data;
while ($dbh->pg_getcopydata($data) >= 0) {
    # process $data
}

The results would be streamed as opposed to being accumulated in
memory. Also COPY is optimized for high performance.

The drawback is you'd have to parse $data according to the
specific rules of the COPY format, which may be easy or
not-so-easy depending on the actual data, numeric or text
or other, whether it has NULLs, backslashes and so on.

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage: http://www.manitou-mail.org


pgsql-general by date:

Previous
From: nill
Date:
Subject: Extracting data from the view to retrieve the foreign key is not declared
Next
From: "Aggarwal, Ajay"
Date:
Subject: Re: replication timeout in pg_basebackup