Thread: Check for prepared statement
Hello all, How can i find out if a prepared statement already exists..? Is there a function or a query i can execute ..?? Best Regards, Fabrizio Mazzoni Macron Srl
-----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 ..?? I have not seen an answer to this, and I am curious as well. Anyone? (Cross-posting to hackers due to the lack of response on general) - -- Greg Sabino Mullane greg@turnstep.com PGP Key: 0x14964AC8 200402172039 -----BEGIN PGP SIGNATURE----- iD8DBQFAMsKDvJuQZxSWSsgRAtbeAJ9mmm3TKSU/hLc+oN3RREzCnM7kkQCfS4TS 6UoHDhGLc8kNyG7F/pT/6IM= =Lg+O -----END PGP SIGNATURE-----
On Wed, Feb 18, 2004 at 01:40:00AM -0000, Greg Sabino Mullane wrote: > Fabrizio Mazzoni asked: > > > How can i find out if a prepared statement already exists..? Is there a > > function or a query i can execute ..?? > > I have not seen an answer to this, and I am curious as well. Anyone? Trying to prepare a dummy query maybe. alvherre=# prepare foo as select 1; PREPARE alvherre=# prepare foo as select 2; ERROR: la sentencia preparada "foo" ya existe alvherre=# execute foo; ?column? ---------- 1 (1 fila) > (Cross-posting to hackers due to the lack of response on general) Wow, you are really desperate. Cc'ed two times! -- Alvaro Herrera (<alvherre[a]dcc.uchile.cl>) "Es filósofo el que disfruta con los enigmas" (G. Coli)
-----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@turnstep.com PGP Key: 0x14964AC8 200406061855 -----BEGIN PGP SIGNATURE----- iD8DBQFAw6G9vJuQZxSWSsgRAkOPAJ9ioEBN2dhUFNdsKzACdLCzEmmrYwCfZY4P 5qkzlSPmdFwmU3vG14pDSmA= =hEeT -----END PGP SIGNATURE-----