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 1q8r0s-00084Q-0U for pgsql-general@arkaria.postgresql.org; Mon, 12 Jun 2023 23:31: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 1q8r0q-0008M3-Sv for pgsql-general@arkaria.postgresql.org; Mon, 12 Jun 2023 23:31: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 1q8r0p-0008K3-Rn for pgsql-general@lists.postgresql.org; Mon, 12 Jun 2023 23:31:52 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q8r0l-0021Ds-GI for pgsql-general@lists.postgresql.org; Mon, 12 Jun 2023 23:31:51 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 874F05C0053; Mon, 12 Jun 2023 19:31:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 12 Jun 2023 19:31:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1686612705; x=1686699105; bh=+y2NjT0Z2qoXM0btEkce750gcKDoxaDt31I E1n7uNVE=; b=dW1ESIvOPVf9u6Y2w/OgJ0Xsz3WAjCXsXBmCP05cAimuiGNRMIs rbGEl+vY8boEe07YEoQvAxzZD2COedWmW10uwbSpTKOx9Pb/NMDvmRAmXMbfPxCu 6E5c5m2mu854bzaSGTBnh2/Xq8cqbsK9OtO1Y4NmlCFkJborhVKZ3BJFHBLrRWgW NzO5XDbspG/Z3NCILpGS12BaOKfriikhErVXtsyQ3C/wQXxojFK8ThsLt6fmJeDn 0g4qplckJ/D1itK7W66eTpwsrAjRiiy4Ju1ykRb/cf2A+bVhYV4nQw21K2gfBxqu uc5CnVrP59v6qVyg1UHG4CTB6Z1mMCumkwA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1686612705; x= 1686699105; bh=+y2NjT0Z2qoXM0btEkce750gcKDoxaDt31IE1n7uNVE=; b=O CZNlnrtXepA4n4Giajsj+/OLXVfXAfO1VmSfkhYx2GK80MmmFPPvy+GVgo6+h4Fb 24EfsQgaLlwqgWaui1ySiXaCe92Jyxinw9wPtZ+NyoNSYUK1yTC1k1GdAIpOkZ4x /lno4wcf3otUv4KH9yjsNv32ZNhTOzNcn3BFKttzUia+3XuMGnkU+1lylzFQDC6d 6BtRrwgtuOGcKtF0PpIS792ax2U2j5+cUTNz9vh29Yy23FrlyP/xI7uFmiQkcjrm 5sM1a0MvHud9UdEUoBBumfrQrnVMYuQUPiWP0Jo/jV4kNMijGVWhzH7BxCfJKhMl tjhy7oJIyr/m5+SUsKrrw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeduiedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelkeegjefhkeetheefudevteehiedvudehkeduleet fedvffeuhedtvdegtdeffeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Jun 2023 19:31:44 -0400 (EDT) Message-ID: <6cef623d-782c-913b-7c9e-6e9be3b0e6d8@aklaver.com> Date: Mon, 12 Jun 2023 16:31:44 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: Re: Dynamic binding issue To: Lorusso Domenico , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/12/23 15:13, Lorusso Domenico wrote: > Hello guys, > I'm a problem with dynamic sql. > I am trying to write a generic function that is able to read and update > a table based on some data coming from e previous record. > Here the example > _sqlStr=format('select * >   from  %1$s.%2$s >   where (' || array_to_string(_activeRec.pk_columns_list, ',') || ') in > (select ' || >   'row($1[''' || array_to_string(_activeRec.pk_columns_list, > '''],$1[''') || ''']))' >   , _activeRec.name_of_schema, _activeRec.main_table); > > execute _sqlStr using oldRec into _rec; > > My problem is oldRec is a type record, so the substitution performed by > execute fails, because it can't recognize the field if the variable is > record and not a specific composite record type. Why not use a row type?: https://www.postgresql.org/docs/current/plpgsql-declarations.html#PLPGSQL-DECLARATION-ROWTYPES > > I suppose this is a recurrent question, but I can't find a solution... > > -- > Domenico L. -- Adrian Klaver adrian.klaver@aklaver.com