Re: Check for prepared statement

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Check for prepared statement
Date: 2004-06-06 22:57:42
Message-ID: a1e2f991f8dd68cce16436f82cce0d7e@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Fabrizio Mazzoni asked:
>>> How can i find out if a prepared statement already exists..? Is
>>> there a function or a query i can execute ..??

Greg replied:
>> I have not seen an answer to this, and I am curious as well. Anyone?

Alvaro Herrera suggested:
> Trying to prepare a dummy query maybe.

Sure, but this creates additional traffic, and causes a transaction
to fail, so it's not really feasible if you are within one. I checked
the pgsql source, and there is no public interface to determine if a
named statement already exists.

I do not know why the original poster needed to know, but I've solved
it within DBD::Pg by simply using the fact that statement names are
not shared across connections and having each connection (that is,
ecah database handle) store an integer starting at 1. Generated
statements are simply named "dbdpg_1", "dbdpg_2", etc. and the
increment is increased only after a statement is created successfully.
There is also support for user-created (and user-named) statements,
with the caveat that it is up to the user, not DBD::Pg, to watch for
name collisions.

- --
Greg Sabino Mullane greg(at)turnstep(dot)com
PGP Key: 0x14964AC8 200406061855

-----BEGIN PGP SIGNATURE-----

iD8DBQFAw6G9vJuQZxSWSsgRAkOPAJ9ioEBN2dhUFNdsKzACdLCzEmmrYwCfZY4P
5qkzlSPmdFwmU3vG14pDSmA=
=hEeT
-----END PGP SIGNATURE-----

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Brendan Jurd 2004-06-06 23:03:13 Re: Turn off "money" formatting?
Previous Message Tom Lane 2004-06-06 22:54:58 Re: Dropping schemas and "illegal seek"

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Pflug 2004-06-07 00:01:18 serverlog function
Previous Message Neeraj Sharma 2004-06-06 21:41:06 Postres dilemma