Re: Prepared statement already exists - Mailing list pgsql-general

From Tomasz Ostrowski
Subject Re: Prepared statement already exists
Date
Msg-id 493CC9EC.5090900@batory.org.pl
Whole thread Raw
In response to Re: Prepared statement already exists  (WireSpot <wirespot@gmail.com>)
Responses Re: Prepared statement already exists
List pgsql-general
On 2008-11-20 12:56, WireSpot wrote:
> On Thu, Nov 20, 2008 at 10:56, Albe Laurenz <laurenz.albe@wien.gv.at> 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 (possibly) benefit from the
> statement being already prepared.
>

So:

sql_md5 = md5(sql);
try {
    PREPARE sql_md5 AS sql;
} catch (SQLException e) {
    if (! e.getSQLState().equals("42P05")) {
        throw e;
    }
}
EXECUTE sql_md5;

Regards
Tometzky
--
...although Eating Honey was a very good thing to do, there was a
moment just before you began to eat it which was better than when you
were...
                                                       Winnie the Pooh

pgsql-general by date:

Previous
From: "Gurjeet Singh"
Date:
Subject: Re: Monty on MySQL 5.1: "Oops, we did it again"
Next
From: WireSpot
Date:
Subject: Re: Prepared statement already exists