pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marc Millas <marc.millas@mokadb.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: prepare in a do loop
Date: Mon, 15 Feb 2021 11:27:49 -0500
Message-ID: <2254393.1613406469@sss.pgh.pa.us> (raw)
In-Reply-To: <CADX_1aa2ZT2aCZJuG4NLZjgUt-QiBiY+P5nKsBSegyhLAq8-jw@mail.gmail.com>
References: <CADX_1aa2ZT2aCZJuG4NLZjgUt-QiBiY+P5nKsBSegyhLAq8-jw@mail.gmail.com>

Marc Millas <marc.millas@mokadb.com> writes:
> in psql, with a postgres 12.5 db on a centos 7 intel:
> I do create a function named randname() returning a varchar, and a table
> matable with a column prenom varchar(50). then
> postgres=# prepare moninsert(varchar) as
> postgres-# insert into matable(prenoms) values($1);
> PREPARE

> I test it:
> postgres=# execute moninsert(randname());
> INSERT 0 1

> up to now, everything fine. then:
> do $$ begin for counter in 1..1000000 loop execute
> moninsert(randname());end loop;end;$$;
> ERREUR:  la fonction moninsert(character varying) n'existe pas
> LIGNE 1 : SELECT moninsert(randname())

> someone can explain ?

EXECUTE in plpgsql has nothing whatever to do with the SQL EXECUTE
command.  See the respective documentation.

You don't actually need to use SQL PREPARE/EXECUTE in plpgsql.
If you just write "insert into ..." as a command in a
plpgsql function, it's automatically prepared behind the scenes.
Indeed, one of the common uses for plpgsql's EXECUTE is to stop
a prepared plan from being used when you don't want that ... so
far from being the same thing, they're more nearly opposites.
Perhaps a different name should have been chosen, but we're
stuck now.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <2254393.1613406469@sss.pgh.pa.us>
Permalink:  ../2254393.1613406469@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2254393.1613406469@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, marc.millas@mokadb.com
  Subject: Re: prepare in a do loop
  In-Reply-To: <2254393.1613406469@sss.pgh.pa.us>
  References: <CADX_1aa2ZT2aCZJuG4NLZjgUt-QiBiY+P5nKsBSegyhLAq8-jw@mail.gmail.com> <2254393.1613406469@sss.pgh.pa.us>

* 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