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 1kopik-0008Ea-52 for pgsql-general@arkaria.postgresql.org; Mon, 14 Dec 2020 15:25:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kopij-0000Mt-3n for pgsql-general@arkaria.postgresql.org; Mon, 14 Dec 2020 15:25:05 +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 1kopih-0000MM-Oe for pgsql-general@lists.postgresql.org; Mon, 14 Dec 2020 15:25:04 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kopie-0003X7-5F for pgsql-general@postgresql.org; Mon, 14 Dec 2020 15:25:03 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 79F205C01BF; Mon, 14 Dec 2020 10:24:57 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 14 Dec 2020 10:24:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=g 8nFngBXzR19zQJ2aWL6dItofQFcUL+XvFsrsf8r33E=; b=ToBR3V8fuaSk+ILfJ fdCPb7XqTCZUt0eWdh1Hp/z0m6ePfTJm0PjyTXfcZnfvTmd0K4Dhwm3F+BeQH0lo VPaAgEP1g385ZHdSLMYPOn5HPotl1qKapYeniIhvW3z8kQ9EzqdifA/rjdlc3m3S DU+IKfBYbC32d5Ia69/+n+XTJ36e64gM0clkOYZULMkDTEm0A/6iJ5fqlwSIhh5j kDYZNBmH+qKkNSWteSq2qd9vIdz9Eav+QgRNV0h6Y1LWbRlDpb98byUudMcppLnb g947FyhwCgPF5ATgoCJuhjQLfQt3bMCrbyd++4XUd2jPTP8wVTWruCE2/+NkGG/s zvj0w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm1; bh=g8nFngBXzR19zQJ2aWL6dItofQFcUL+XvFsrsf8r3 3E=; b=VAuB+acQLF3rx+S/NgY8Ntkc4bvrshmGPgXkcb0mTJc6Zx7KLo30ZfYe4 PqnAYbXPAjMtBmHvV+yCMofeBAARGDhzCfFTq8F8n5YRpFVg1bJXmXy+BD8LBXoh WyUtPP4/VV+AcStm/EH2/rhryFjerAwK3RIZ+4ORxuxfqmLtfVW74uSdH500zzfv sFFrfAHN9WcVAnZsmEiHsg3XWUYMyhB5boh74NK5FTkM1rwafkDVXg1eWIrvFbu/ R8ZRtu54v80QmbzAN3wAXS6poLU6OAjC18+Hh1Q990LUBY1dCOoEf4z8PGVBcXwy +W2A7p8ahQrWJOY+7/CGb20Z5qSGg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudekkedgjeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepuddufeejte evffehgfduhedthfdvteekieeuheefveevudetkeelueehgeduhefhnecuffhomhgrihhn pehpohhsthhgrhgvshhqlhdrohhrghenucfkphepjeehrddujedvrddurdeileenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.4] (75-172-1-69.tukw.qwest.net [75.172.1.69]) by mail.messagingengine.com (Postfix) with ESMTPA id B73771080068; Mon, 14 Dec 2020 10:24:56 -0500 (EST) Subject: Re: Dynamic procedure execution To: "Muthukumar.GK" , "pgsql-general@postgresql.org >> PG-General Mailing List" References: From: Adrian Klaver Message-ID: <5991c08b-6136-b6a9-4979-50d1b355ecdb@aklaver.com> Date: Mon, 14 Dec 2020 07:24:55 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.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 12/13/20 9:59 PM, Muthukumar.GK wrote: > Hi team, > > When I am trying to implement belwo dynamic concept in postgreSql, > getting some error. Kindly find the below attached program and error. > Please advise me what is wrong here.. > > CREATE OR REPLACE PROCEDURE DynamicProc() > > AS $$ > > DECLARE v_query TEXT; > > C1 refcursor := 'result1'; > > begin > > v_query := ''; > > v_query := ' OPEN C1 FOR SELECT * FROM public."Bankdetails"'; > > EXECUTE (v_query); > > END; > > $$ > > Language plpgsql; > >  Calling procedure :- > > -------------------------------- > > CALL DynamicProc(); > > FETCH ALL IN "result1"; > > > Error :- > > -------------- > > ERROR: syntax error at or near "OPEN" > > LINE 1: OPEN C1 FOR SELECT * FROM public."Los_BankInfo" ^ > > QUERY: OPEN C1 FOR SELECT * FROM public."Los_BankInfo" > > CONTEXT: PL/pgSQL function dynamicproc() line 9 at EXECUTE SQL state: 42601 Two things: 1) The error is from a different version of the procedure then the code. The table name is different. Can't be sure that this is the only change. So can you synchronize your code with the error. 2) Take a look here: https://www.postgresql.org/docs/12/plpgsql-cursors.html 42.7.2. Opening Cursors For why OPEN is plpgsql specific and how to use it. > > > Regards > > Muthukumar.gk > -- Adrian Klaver adrian.klaver@aklaver.com