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 1qiE4a-005aPX-Jb for pgsql-sql@arkaria.postgresql.org; Mon, 18 Sep 2023 13:13:56 +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 1qiE4Z-000o3r-2P for pgsql-sql@arkaria.postgresql.org; Mon, 18 Sep 2023 13:13:55 +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 1qiE4Y-000o3d-Ox for pgsql-sql@lists.postgresql.org; Mon, 18 Sep 2023 13:13:54 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qiE4W-005tyz-7q for pgsql-sql@postgresql.org; Mon, 18 Sep 2023 13:13:54 +0000 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-502153ae36cso7142380e87.3 for ; Mon, 18 Sep 2023 06:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695042831; x=1695647631; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mrs2EniPeBPoWhhcYJoZYX+M/vZLrteZaQvC+5f7Pgo=; b=PTueK0hXbLSQ6HczgoSW/6Nfxwh25Q+qClX/LfMjOEk77qFKnozE6iYPyOVueYA5Wt TEBBtl2bFYr+NVIAUSDuQrqHjcG+rGuqnIG1hM5zhjWayyJ5KVC5684GT+7duhxZgXGB RdvehFp1R27Jtb2O0Be4jmzjUbCf/rZGiA53N4U0eCZCu0/drofFcLD3114gocRoru6X f2QUKKC91khPDBWzUdm2xq4D1JPBu036kwa49CafZBXvPER/1Kj1rMyCyGCYAb8rxl3B n8ZXr/9RkJ2yVYO++NDqYzkN1bQ+tISNpCP1N1KLnzrgC+NDLlcQzLQE08IFD1vb+j+B WYDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695042831; x=1695647631; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mrs2EniPeBPoWhhcYJoZYX+M/vZLrteZaQvC+5f7Pgo=; b=bmqMSc7QnQDmijYQuQ97qXVuaf3IeCBo3KRhsGf4AbD4/eeukYAXAy9CiIpPQQHwFI nlMnh8kKNcM2ZR8AW5Wmt7gcepLzC1p+J3wZh5jQ9bkxwHsVsRd4agK1LDhIiGkijtSu tffPiijn4sfWaj2OFRVKBO27JXpUZVrX9P006P0gEVnrYMuy+AhVucogOeJtIUTG9Dpq YMTlY9x4td0UFhp4T8OPZwWIY09J8HmwU/9Xeg4SnWW15VhJGpNkIpvyjyLgUBEoaNQS KRml5vDUrW67T4SkEEk07GPILARJM7fw3/uR3/LSIUsc6c9zYfnnGUG23uYR7vw4Bzlk xiuA== X-Gm-Message-State: AOJu0YxJ0uSY2abxjPGs7b3NWrRqN2GY/YLPW8y8/HXmuwp0xvk7N3Ux s78YTGNV8TJQ/73kfBChhl8lOwcsfgu2XDxRbVkyCgAk6kU= X-Google-Smtp-Source: AGHT+IFFkP3YyYNbV3CQ9xkwQG0n4itwYSITRl5JPzGixzmoHNM5BMewzdxbKMKsLpvOmPbrBDzjIfrMbXaDo2Ul8Dk= X-Received: by 2002:a05:6512:33c8:b0:4fe:d0f:b4f7 with SMTP id d8-20020a05651233c800b004fe0d0fb4f7mr9823460lfg.65.1695042831223; Mon, 18 Sep 2023 06:13:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Tue, 19 Sep 2023 01:13:40 +1200 Message-ID: Subject: Re: no_data_found oracle vs pg To: "Jean-Marc Voillequin (MA)" Cc: Pavel Stehule , "pgsql-sql@postgresql.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 18 Sept 2023 at 18:49, Jean-Marc Voillequin (MA) wrote: > I know I can test the ROWCOUNT or the FOUND indicator, but it=E2=80=99s n= ot what I want. > > I want a NO_DATA_FOUND exception to be raised when the function is called= from a PL/pgSQL block, and I want the function to return a NULL value when= called from SQL. It would mean having to include logic in each function, but perhaps GET DIAGNOSTIC PG_CONTEXT could be of some use. You could adapt the following to call the STRICT or non-STRICT version accordingly. create or replace function myfunc() returns int as $$ declare ctx text; begin GET DIAGNOSTICS ctx =3D PG_CONTEXT; if split_part(ctx, E'\n', 2) =3D '' then raise notice 'top level'; else raise notice 'nested'; end if; return 1; end; $$ language plpgsql; create or replace function callerfunc() returns int as $$ begin return myfunc(); end; $$ language plpgsql; select myfunc(); select callerfunc(); David