Re: [GENERAL] Prepared statement already exists

2008-12-09 Thread Scott Marlowe
On Tue, Dec 9, 2008 at 8:59 PM, Chris <[EMAIL PROTECTED]> wrote: > Richard Huxton wrote: >> >> WireSpot wrote: >>> >>> This mechanism is still not perfect. Technically it is still possible >>> for race conditions to appear. Apparently (in PHP at least) pg_connect >>> does persistent connections by

Re: [GENERAL] Prepared statement already exists

2008-12-09 Thread Chris
Richard Huxton wrote: WireSpot wrote: This mechanism is still not perfect. Technically it is still possible for race conditions to appear. Apparently (in PHP at least) pg_connect does persistent connections by default. Nope - pg_pconnect() does that. Multiple calls to pg_connect() within the s

Re: [GENERAL] Prepared statement already exists

2008-12-08 Thread Richard Huxton
WireSpot wrote: > This mechanism is still not perfect. Technically it is still possible > for race conditions to appear. Apparently (in PHP at least) pg_connect > does persistent connections by default. Nope - pg_pconnect() does that. Multiple calls to pg_connect() within the same script will give

Re: [GENERAL] Prepared statement already exists

2008-12-07 Thread WireSpot
On Mon, Dec 8, 2008 at 09:17, Tomasz Ostrowski <[EMAIL PROTECTED]> wrote: > So: > > sql_md5 = md5(sql); > try { >PREPARE sql_md5 AS sql; > } catch (SQLException e) { >if (! e.getSQLState().equals("42P05")) { >throw e; >} > } > EXECUTE sql_md5; Yeah, well, li

Re: [GENERAL] Prepared statement already exists

2008-12-07 Thread Tomasz Ostrowski
On 2008-11-20 12:56, WireSpot wrote: On Thu, Nov 20, 2008 at 10:56, Albe Laurenz <[EMAIL PROTECTED]> wrote: Do you still need the old prepared statement? If not, you can simple DEALLOCATE it and then try the PREPARE again. Yes, I'd like to keep the old statements, that's part of the perks --

Re: [GENERAL] Prepared statement already exists

2008-11-21 Thread Daniel Verite
Alvaro Herrera wrote: In this case, why not just prepare all the needed statements at the first use of the session by the pool software? In theory yes, but I can't imagine how it could be done in practice. The pool software is typically a middleware and the application isn't even awa

Re: [GENERAL] Prepared statement already exists

2008-11-21 Thread Alvaro Herrera
Daniel Verite wrote: > Also contrary to prepared statements, maybe that cache would be shared > between connections, and that would be excellent, since it fits the > typical usage pattern of websites: a high-throughput of a small set of > low-latency queries, fired from pooled connections.

Re: [GENERAL] Prepared statement already exists

2008-11-21 Thread Daniel Verite
WireSpot wrote: So it would eliminate the possibility of clashes, but do nothing for statement reuse. Agreed. What would make it all the way better was if the database would do that last step for you as well: automatically recognize statements that do the same thing and return the a

Re: [GENERAL] Prepared statement already exists

2008-11-21 Thread Sam Mason
On Fri, Nov 21, 2008 at 09:55:11AM +0200, WireSpot wrote: > What would make it all the way better was if the database would do > that last step for you as well: automatically recognize statements > that do the same thing and return the already existing handle. This is somewhat difficult; things to

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread WireSpot
On Thu, Nov 20, 2008 at 19:19, Daniel Verite <[EMAIL PROTECTED]> wrote: > By the way, why do the prepared statements require to be named at all? > With other DBMS such as oracle or mysql, one can prepare statements without > providing any name for them: the prepare() step returns a "statement handl

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Daniel Verite
Albe Laurenz wrote: You'll have to find a way to pick or generate unique names for the prepared statements. You could check for name collisions and disambiguate with a suffix or something. By the way, why do the prepared statements require to be named at all? With other DBMS such as or

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread WireSpot
On Thu, Nov 20, 2008 at 16:07, Alvaro Herrera <[EMAIL PROTECTED]> wrote: > I guess if connections are persistent, you could clear them before each > usage with DISCARD (8.3 only) Again, I'd be losing the advantage of the already prepared statements. Basically, what it comes down it is I want to be

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Sam Mason
On Thu, Nov 20, 2008 at 04:03:08PM +0200, WireSpot wrote: > On Thu, Nov 20, 2008 at 15:45, Sam Mason <[EMAIL PROTECTED]> wrote: > > Have you thought about using stored procedures instead of prepared > > statements? No need to register them or keep track of that state. > > I'm not sure if it would

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Alvaro Herrera
WireSpot escribió: > I guess he means if connections are persistent, or if the same > connection is being used at the same time from different parts of the > application. I guess if connections are persistent, you could clear them before each usage with DISCARD (8.3 only) -- Alvaro Herrera

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread WireSpot
On Thu, Nov 20, 2008 at 15:45, Sam Mason <[EMAIL PROTECTED]> wrote: > On Wed, Nov 19, 2008 at 09:42:33PM +0200, WireSpot wrote: >> I also imagined some workarounds in the code (PHP), such as defining a >> global/static hash table and registering statement names with it. But >> I'd like to know if t

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Sam Mason
On Wed, Nov 19, 2008 at 09:42:33PM +0200, WireSpot wrote: > I also imagined some workarounds in the code (PHP), such as defining a > global/static hash table and registering statement names with it. But > I'd like to know if there's a better way. Have you thought about using stored procedures inst

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread WireSpot
> Merlin Moncure escribió: >> pg_prepared_statements (on recent versions of postgresql) Thank you, that's one of the things I wanted to know. On Thu, Nov 20, 2008 at 15:30, Alvaro Herrera <[EMAIL PROTECTED]> wrote: > Merlin Moncure escribió: >> also, watch out for race conditions. > > What race c

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Alvaro Herrera
Merlin Moncure escribió: > On Wed, Nov 19, 2008 at 2:42 PM, WireSpot <[EMAIL PROTECTED]> wrote: > > 3) Reading a list of all the currently defined prepared statements to > > see if the one I want is already prepared. I'm hoping some "magic" > > SELECT in pg's internal tables may do the trick. But

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Albe Laurenz
Please, send your replies to the list as well. WireSpot wrote: > > Do you still need the old prepared statement? > > > > If not, you can simple DEALLOCATE it and then try the PREPARE again. > > Yes, I'd like to keep the old statements, that's part of the perks -- > if a query will be repeated it

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Merlin Moncure
On Wed, Nov 19, 2008 at 2:42 PM, WireSpot <[EMAIL PROTECTED]> wrote: > I'm trying to use prepared statements in an application and I'm > running into this error: "Query failed: prepared statement already > exists". > > The reason is obvious. What I want to know is the best way to avoid > getting th

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread WireSpot
On Thu, Nov 20, 2008 at 10:56, Albe Laurenz <[EMAIL PROTECTED]> wrote: > Do you still need the old prepared statement? > > If not, you can simple DEALLOCATE it and then try the PREPARE again. Yes, I'd like to keep the old statements, that's part of the perks -- if a query will be repeated it will

Re: [GENERAL] Prepared statement already exists

2008-11-20 Thread Albe Laurenz
WireSpot wrote: > I'm trying to use prepared statements in an application and I'm > running into this error: "Query failed: prepared statement already > exists". > > The reason is obvious. What I want to know is the best way to avoid > getting this error. The client application sets statement name

[GENERAL] Prepared statement already exists

2008-11-19 Thread WireSpot
I'm trying to use prepared statements in an application and I'm running into this error: "Query failed: prepared statement already exists". The reason is obvious. What I want to know is the best way to avoid getting this error. The client application sets statement names as MD5 of the actual query

Re: [GENERAL] prepared statement already exists

2006-08-14 Thread Michael Fuhr
On Sun, Aug 13, 2006 at 10:48:37AM -0700, Jim Bryan wrote: > Hi! In a function to insert rows into a table, I keep > getting ERROR: prepared statement "updateplan" already > exists. If any ideas; thanks. As the error says, you already have a prepared statement named "updateplan". To reuse that

[GENERAL] prepared statement already exists

2006-08-14 Thread Jim Bryan
Hi! In a function to insert rows into a table, I keep getting ERROR: prepared statement "updateplan" already exists. If any ideas; thanks. CREATE OR REPLACE FUNCTION testPreparedStatement() RETURNS SETOF FLOAT AS $$ DECLARE tryint1 int4:=1 ; tryint2 int4:=2 ; BEGIN PREPARE updatePlan