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

From Michael Fuhr
Subject Re: prepared statement already exists
Date
Msg-id 20060814152948.GA93423@winnie.fuhr.org
Whole thread Raw
In response to prepared statement already exists  (Jim Bryan <gooddayarizona@yahoo.com>)
List pgsql-general
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 name you'll need to DEALLOCATE it
first.  However, then you'll get the following error:

test=> SELECT testPreparedStatement();
ERROR:  function updateplan(integer, integer) does not exist

That's because the PL/pgSQL command EXECUTE is different than the
SQL command EXECUTE:

http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

You don't need to use prepared statements in PL/pgSQL functions
because the language automatically prepares and caches query plans.
Just do the INSERT directly.

--
Michael Fuhr

pgsql-general by date:

Previous
From: AgentM
Date:
Subject: Re: Best approach for a "gap-less" sequence
Next
From: Jorge Godoy
Date:
Subject: Re: Best approach for a "gap-less" sequence