Re: prepare in a do loop - Mailing list pgsql-general

From Adrian Klaver
Subject Re: prepare in a do loop
Date
Msg-id 3d94209d-b100-0f07-e2b0-213d4467e870@aklaver.com
Whole thread Raw
In response to Re: prepare in a do loop  (Marc Millas <marc.millas@mokadb.com>)
List 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.klaver@aklaver.com



pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: certs in connection string
Next
From: Alvaro Herrera
Date:
Subject: Re: How to post to this mailing list from a web based interface