Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBiIo-00025c-JI for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 18:08:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lBiIm-0002Cm-Bj for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 18:08:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBiIm-0002C4-43 for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 18:08:52 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lBiIj-0008El-O8 for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 18:08:51 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id B7E815C00F5; Mon, 15 Feb 2021 13:08:47 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 15 Feb 2021 13:08:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=4 hoioqOkUQrK/Bm5h7Yz1l+Sq+S9Y5d5a0E5k3eeGcY=; b=y02W13sygtK4XZWkF V7UzjG9on2f82ABuI80WczUP1gKWdk2wugUgF3kihq7wJreM7qmJcj+Y/N8Zauva 1pFM6xQuyzF+rfS6S4VEV6m7AoDwGilqaYSG5YhEeErh2XaLzMjTXmjGQXEPYRtm Trjnp/SLGlU8U1B7LPBRYCFuL843jf+PG5ttY5U9WSECAm5yA/Xkr95/m4wuTjEb vulThYYCiU+cJWtPWef6KTwfRJ18YSkkmnEV8vIZoBnUFA+8SuClqOQfAb7NES+G nFVaCoIQtl2cULnXj4LV2U7W9RjIAI0SCwC74FLicHt8JkaQ4FUVZB/xCDi9nI3G 0acZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=4hoioqOkUQrK/Bm5h7Yz1l+Sq+S9Y5d5a0E5k3eeG cY=; b=MgInn2TgRrO1xwS58v5A8d7mBDyRWFdtss91/KSQeWCH0R4/wn/DXtGZV tbbbwYkDveQaPLaZfUf5CzpCqyICk+KTSoJxbCM7q46lmRaDBc5T1qFVDY6GJsa3 QNfllGyxk0Yk8LJbYXjx9qeyoU5kluafJx+A1u4dHmfYiRPDoQkVCDv+dMlkm/K5 NPpSTIN44SAME4vzMS5h4fPPm573zgO8k4rZYiwT+RCo6MkLQMpkLa03nznzYclI RaMLlpQ9C9BSK7u7QsmL/ba0c+y3kg5V1AqXuD70sJpTh+txqag4yKzJlY5XuFaO JSp+bhKFyPkPrf78AIKD98RHaImCg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrieekgddutdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeevveefveefueegffekkefhgeeiueffgfetueejvdfg hfeujeejhfekjeelgedtgeenucfkphepleejrdduudefrddvudejrddvjeenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.4] (97-113-217-27.tukw.qwest.net [97.113.217.27]) by mail.messagingengine.com (Postfix) with ESMTPA id AD8571080067; Mon, 15 Feb 2021 13:08:46 -0500 (EST) Subject: Re: prepare in a do loop To: Marc Millas , Tom Lane Cc: "pgsql-general@lists.postgresql.org" References: <2254393.1613406469@sss.pgh.pa.us> From: Adrian Klaver Message-ID: <3d94209d-b100-0f07-e2b0-213d4467e870@aklaver.com> Date: Mon, 15 Feb 2021 10:08:45 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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