pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Milen Kulev <makulev@gmx.net>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: Prepared statements in PGSQL functions
Date: Wed, 14 Jun 2006 17:16:39 +0200
Message-ID: <012701c68fc5$895d24f0$0a00a8c0@trivadis.com> (raw)
In-Reply-To: <23768.1150295728@sss.pgh.pa.us>



-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Tom Lane
Sent: Wednesday, June 14, 2006 4:35 PM
To: Milen Kulev
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Prepared statements in PGSQL functions 


"Milen Kulev" <makulev@gmx.net> writes:
>> I want to use prepared statement in a function (your comments below).  Wanted
 just to test the difference ...

Why?  You seem not to be aware that plpgsql implicitly prepares statements behind the scenes.

&&>> I already have a version with "direct" insert ( just as you say a couple of lines below)

> 		prepare  mystmt( int, int, varchar)	as insert into part values ($1,$2,$3);
> 		execute  mystmt(v_id1, v_id2, v_filler );
> 		deallocate mystmt;

If that worked it would be *exactly* the same as just doing

		insert into part values (v_id1, v_id2, v_filler);

except for being slower due to re-preparing each time through the function.  So don't waste your time trying to outsmart
the language.

>> My idea was to prepare the statment once and execute it in a loop  many times (within a procedure/function).  Anyway,
obviously there is no performance gain in using prepared statement in functions.
Regards. Milen 

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend




view thread (4+ messages)

Message-ID: <012701c68fc5$895d24f0$0a00a8c0@trivadis.com>
Permalink:  ../012701c68fc5$895d24f0$0a00a8c0@trivadis.com/
Also on:    postgresql.org/message-id/012701c68fc5$895d24f0$0a00a8c0@trivadis.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: makulev@gmx.net, tgl@sss.pgh.pa.us
  Subject: Re: Prepared statements in PGSQL functions
  In-Reply-To: <012701c68fc5$895d24f0$0a00a8c0@trivadis.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox