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 1sxpSs-00ChEy-Qv for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2024 15:16:02 +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 1sxpSr-00CFrN-F1 for pgsql-general@arkaria.postgresql.org; Mon, 07 Oct 2024 15:16:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sxpSr-00CFoA-3D for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2024 15:16:01 +0000 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sxpSo-002yIv-Mi for pgsql-general@lists.postgresql.org; Mon, 07 Oct 2024 15:15:59 +0000 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-71dff3b3c66so836742b3a.0 for ; Mon, 07 Oct 2024 08:15:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728314158; x=1728918958; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=dV/9FOa55xHEDukmcOTjgq+SBgjj0BqVznNKbTLbrRs=; b=NayG580PUp8e4Q6h/gn0Z5uA2ymR2t8L2fKh9+fItrx5IXtuXCDqd7QFZHmgLQIekH g8u13n1b4eNwUBID/Gs99LRcqh8IHe1+J80MM6Xq06SzXTV5sHvnfLZT/URnMcx5eeC3 Mvl742r2Hk011w+VGm8l/cKFm8WtYPWcDjF1gr6i9lJa71jerm1wkmB+XKyTqwKqBlUo FT++aKO3mQhBNBaysSDiVDSvVAmLfMEsYurcuUiSMbsocOH1PTKezz3pniUvE2uPbQsY TozJ53OthaT6SvHs5HVOhV2sa21OceNFugX2TwPOxO8bDst2dXYT+W9KV3m/ECdhaIt4 t2sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728314158; x=1728918958; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dV/9FOa55xHEDukmcOTjgq+SBgjj0BqVznNKbTLbrRs=; b=D5eesTcR4xYi0InOyIlA7vlmvZpGV/M4venYptu3vFi/7g7B7fW/h7RnquiLrcTvIb MJhyoPlvAf1sxH+QPbSUFVD9BgI2DSG8OHzQdZYP1Es0Raw3WMwlj5iqGnuycXxeif3t Vmx23QvhFckM5Lv3GhizG2Z477127YoGp07NAPWtGzlclvnWsa35IguZMv5YaZnAE2fX 4i7xc5atdD5SbCqzb1y6wdTbtIFI9L74umSS8z6dFeQuqOQzJ66nyQWP7OoQ6UvQEoDq 4et3UMPOmso3qo3K240WOKmqgmjkFlqQ0+p7mApZb5edXSVEdjwPBejmzeigV9fg8RpN b26w== X-Gm-Message-State: AOJu0YyO/G2eGjq+aaD/ky2qDMAfSZ8KfToxZjQKFJwd8Wyj4hxzy8AL leGAYSMfJ+aach8s3qZBV2tASKjOwcmC8ss+GM/7lxVICeudQEKn5vqXZSi6W5+6+ZE+hJSsnVk qXaE8nKyxaZr6scFqpI3/2qSEqJY9H+ZHoPMA1g== X-Google-Smtp-Source: AGHT+IE8U6Zg5BU4pTQIRpHFbr3GcgoZq73z6ObSWh6GZ0rpeb3yUFqO4LW6O2A7P88qrRjcYSq+22s6S3/GseNW1A4= X-Received: by 2002:a05:6a00:2d10:b0:71e:9a8:2b9a with SMTP id d2e1a72fcca58-71e09a82ddfmr3222850b3a.23.1728314157825; Mon, 07 Oct 2024 08:15:57 -0700 (PDT) MIME-Version: 1.0 From: PetSerAl Date: Mon, 7 Oct 2024 18:15:48 +0300 Message-ID: Subject: Get cursor name for invalid_cursor_name error To: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 ------------------------ (1 row) postgres=# BEGIN; BEGIN postgres=*# DECLARE "fgh" SCROLL CURSOR FOR VALUES (value_from_cursor_unsafe('jkl')); DECLARE CURSOR postgres=*# SELECT value_from_cursor_safe('fgh'); -- case 2 INFO: cursor "jkl" does not exist value_from_cursor_safe ------------------------ (1 row) postgres=*# COMMIT; COMMIT For example, in given example in "case 2" I want to rethrow error, because it is not about 'fgh' cursor, which I directly query. But it seems cursor name only available as part of localizable error message, but not as separate field through GET STACKED DIAGNOSTICS.