Re: libpq - lack of support to set the fetch size

From: "Daniel Verite" <daniel(at)manitou-mail(dot)org>
To: "matshyeq" <matshyeq(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: libpq - lack of support to set the fetch size
Date: 2014-03-10 19:12:24
Message-ID: 5699fc18-f65e-43b2-b73e-6c72ef2d7b3d@mm
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Aggarwal, Ajay 2014-03-10 20:07:45 Re: replication timeout in pg_basebackup
Previous Message bricklen 2014-03-10 17:51:09 Re: Playing with 9.4devel - unnest