Re: Prepared statement already exists

From: Tomasz Ostrowski <tometzky(at)batory(dot)org(dot)pl>
To: WireSpot <wirespot(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Prepared statement already exists
Date: 2008-12-08 07:17:00
Message-ID: 493CC9EC.5090900@batory.org.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2008-11-20 12:56, WireSpot wrote:
> On Thu, Nov 20, 2008 at 10:56, Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message WireSpot 2008-12-08 07:41:41 Re: Prepared statement already exists
Previous Message Gurjeet Singh 2008-12-08 05:54:25 Re: Monty on MySQL 5.1: "Oops, we did it again"