Re: prepared statement already exists

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Jim Bryan <gooddayarizona(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: prepared statement already exists
Date: 2006-08-14 15:29:48
Message-ID: 20060814152948.GA93423@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jorge Godoy 2006-08-14 15:32:21 Re: Best approach for a "gap-less" sequence
Previous Message Tom Lane 2006-08-14 15:27:00 Re: BUG #2574: C function: arg TEXT data corrupt