Re: General question about DBI/DBD - Mailing list pgsql-general

From Doug McNaught
Subject Re: General question about DBI/DBD
Date
Msg-id m3pu6ruc8f.fsf@belphigor.mcnaught.org
Whole thread Raw
In response to problem connecting client to a postgresSQL server  ("darwin" <dharval@digitelone.com>)
List pgsql-general
Paul Tomblin <ptomblin@xcski.com> writes:

[converting Pg.pm to DBD::Pg]

> Also, the big program does a whole bunch of
>   $conn->exec("SELECT * FROM tablename WHERE indexed_column = '$key'");
> and things like that.  Is there a way in DBD:Pg I can re-parse those
> queries with "...indexed_column = :1" and then supply a different key each
> time?  I remember when I used to write C programs that accessed Oracle
> (about 8 years ago, so the details are hazy), that was a major performance
> improvement.

You can basically do:

$stmt = $dbh->prepare("SELECT * FROM tablename WHERE indexed_column = ?");

$stmt->execute($key1);
$stmt->execute($key2);

This is nice because it will do any escaping in $key that needs to be
done.

However, PG doesn't cache query plans in this situation (unlike
Oracle) so you won't see a big performance win.

(Apologies if my syntax is off; I mostly use Java now.)

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
   --T. J. Jackson, 1863

pgsql-general by date:

Previous
From: "Greg Sabino Mullane"
Date:
Subject: Re: Help installing PGSQL 7.1 on Linux
Next
From: qradius@qnet.com.pe
Date:
Subject: How to view the functions that exists