Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sxpe5-00CiTR-Oq for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2024 15:27:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sxpe3-00CNYH-Cx for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2024 15:27:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sxpe2-00CNXL-G2 for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2024 15:27:35 +0000 Received: from fout-a6-smtp.messagingengine.com ([103.168.172.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sxpdz-0032oD-9n for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2024 15:27:33 +0000 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.phl.internal (Postfix) with ESMTP id 9FA91138022E; Mon, 7 Oct 2024 11:27:29 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Mon, 07 Oct 2024 11:27:29 -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:subject:subject:to:to; s=fm1; t=1728314849; x=1728401249; bh=UDAoBnqi5Mx50K5xO5B8ZD0I2PwG8MXvZGLlDi9UAa8=; b= YZSPvmVlNRSiQKVXafc8RNBmG2ARkGs2pmE7sHD06V+HO4ggD9xMNgiGDqgEzbKd 89OULGhbbVVnZ3FHSMS9cpw6q/A0pchKQjk22nAZBmBDXPLyvSq1PukO92KKO6D8 JGGWAL8lGw6Q4zBedJ3nj5BpN9TvK/uZTSvSYC2EtNcV9mlm9PiHweMPcmaqaPPj fNhUep1WduXna4vhGfLW1S90yg+m4kU0UiEO3Z+Yv0Pd+geBs5WxjTJ9bKVxzvzx buyBlqo3YI5kJto6Vfj67fKvINF/JvOvve+VuBHRIbN07Bhw3Hcx2LaFKR/rGmf5 14La9h8D8NTFk7p/8EnBYg== 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:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1728314849; x= 1728401249; bh=UDAoBnqi5Mx50K5xO5B8ZD0I2PwG8MXvZGLlDi9UAa8=; b=O YLK54VnibcjwwfmiIUBpU1Bg2g9xKsaoOxPiV/LB9Vbij+NsdYfRR+Z1UJBW+Oo8 ANwkIe5RccAz5rOPMzzXAMY2fwVORjrDlBYDwC4oLKAF7ooJEflFSbOfnSIMSbae fjTQuMu4CIa407TCRFg5KRVz4b7lvy3brpNSowEPnTg0qu8tqCHmnPMa6bbH5lTj fcmjvTTnOU1+GCBsXgekXg6pEiF3RtWTP4GaurkW4BlWUp1+COlJ7S87TJSqm++R ynzIyYs0JYt807rjWHa/4GQSreCrh3RFg/JbUjrXcpuvLyEx6xDIfhL8G+Wbv+tf EirbAGPVf9jhVzQHNYrdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvddvledgkeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfg fuvfhfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghr uceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrth htvghrnhepiedvhfeiheehgeeuieeljeeitedtjeehudegfeelkedvleekhedtgfeiffef kedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg gurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdpnhgspghrtghpthhtohep vddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepphgvthhsvghrrghlsehgmhgrih hlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphho shhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 7 Oct 2024 11:27:29 -0400 (EDT) Message-ID: <72db04f3-d064-44f6-9a55-dfdcb88b0937@aklaver.com> Date: Mon, 7 Oct 2024 08:27:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Get cursor name for invalid_cursor_name error To: PetSerAl , 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: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/7/24 08:15, PetSerAl wrote: > How to reliable get cursor name which cause invalid_cursor_name error? > > postgres=# CREATE FUNCTION value_from_cursor_unsafe(cursor_name text) > RETURNS integer > postgres-# STRICT LANGUAGE plpgsql > postgres-# AS $$ > postgres$# DECLARE > postgres$# cursor CONSTANT refcursor NOT NULL := cursor_name; > postgres$# result integer; > postgres$# BEGIN > postgres$# FETCH FIRST FROM cursor INTO result; > postgres$# return result; > postgres$# END > postgres$# $$; > CREATE FUNCTION > postgres=# CREATE FUNCTION value_from_cursor_safe(cursor_name text) > RETURNS integer > postgres-# STRICT LANGUAGE plpgsql > postgres-# AS $$ > postgres$# DECLARE > postgres$# result integer; > postgres$# BEGIN > postgres$# BEGIN > postgres$# result := value_from_cursor_unsafe(cursor_name); > postgres$# EXCEPTION > postgres$# WHEN invalid_cursor_name THEN > postgres$# RAISE INFO '%', SQLERRM; > postgres$# END; > postgres$# return result; > postgres$# END > postgres$# $$; > CREATE FUNCTION > postgres=# SELECT value_from_cursor_safe('asd'); -- case 1 > INFO: cursor "asd" does not exist > value_from_cursor_safe > ------------------------ FYI, if you do \ef value_from_cursor_unsafe the function definition will appear in an editor and from there you can copy and paste to make the output easier to follow. -- Adrian Klaver adrian.klaver@aklaver.com