Re: prepare in a do loop

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Marc Millas <marc(dot)millas(at)mokadb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: prepare in a do loop
Date: 2021-02-15 18:08:45
Message-ID: 3d94209d-b100-0f07-e2b0-213d4467e870@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/15/21 9:55 AM, Marc Millas wrote:
> Hi Tom,
>
> I do read the doc, and understand the caching behaviour of plpgsql.

This is not about plpgsql caching. It is about EXECUTE in plpgsql
meaning something different then the PREPARE/EXECUTE combination in SQL.
You are trying to run EXECUTE moninsert(randname()) in plpgsql where
moninsert was a PREPARE statement. In plpgsql EXECUTE is something
different so it does not recognize moninsert(randname()) as a prepared
statement and fails.

> if in psql I write begin;execute moninsert(randname()); execute
> moninsert(randname());end;
> it does work.  And if I put this (begin execute end) inside a do loop it
> doesnt anymore.
> ok the begin execute end is ""pure"" SQL, and the same thing within a do
> loop is plpgsql
> so
> postgres=# create function testexec()returns void as $$
> postgres$# execute moninsert(randname());
> postgres$# end;
> postgres$# $$ language plpgsql;
> ERREUR:  erreur de syntaxe sur ou près de « execute »
> LIGNE 2 : execute moninsert(randname());
> fine, quite coherent.
> then

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2021-02-15 18:41:00 Re: How to post to this mailing list from a web based interface
Previous Message Rob Sargent 2021-02-15 18:01:00 Re: certs in connection string