Re: DBD::Pg/perl question, kind of...

From: "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at>
To: "Neal Clark *EXTERN*" <nclark(at)securescience(dot)net>, "PostgreSQL General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: DBD::Pg/perl question, kind of...
Date: 2007-03-12 09:10:10
Message-ID: AFCCBB403D7E7A4581E48F20AF3E5DB2019DAB24@EXADV1.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Neal Clark wrote:
> my $sth = $dbh->prepare(qq{SOME_QUERY});
> $sth->execute;
> while (my $href = $sth->fetchrow_hashref) {
> # do stuff
> }
>
[...]
>
> So with mysql, I can just say $dbh->{'mysql-use-result'} = 1, and
> then it switches so that the fetchrow_hashref calls are actually
> fetching from the database, and I only have one row in memory at a
> time, unless I copy the reference and let it wander off somewhere
> else, or something.
>
> So all I'm really asking is, how does postgre approach the use result/

> store result issue? Can I easily process result sets that are larger
> than memory? And if it handles it similar to mysql, does it also
> cause the same table locking behaviour?

The man page of DBD::Pg says, and my experiments with tcpdump confirm:

RowCacheSize (integer)
Implemented by DBI, not used by this driver.

And more:

Cursors

Although PostgreSQL has a cursor concept, it has not been used in the
current implementation. Cursors in PostgreSQL can only be used inside
a
transaction block. Because only one transaction block at a time is
allowed, this would have implied the restriction not to use any
nested
"SELECT" statements. Hence the "execute" method fetches all data at
once into data structures located in the front-end application. This
approach must to be considered when selecting large amounts of data!

So there is no automatic way of handling it.

You will probably have to consider it in your code and use
SELECT-Statements
with a LIMIT clause.

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2007-03-12 09:33:47 Re: %tsearch gendict snowball spanish
Previous Message Neal Clark 2007-03-12 05:43:35 DBD::Pg/perl question, kind of...