From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | "Jean-Marc Voillequin (MA)" <Jean-Marc(dot)Voillequin(at)moodys(dot)com> |
Cc: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: no_data_found oracle vs pg |
Date: | 2023-09-18 13:13:40 |
Message-ID: | CAApHDvrhBh9PwphEUH973mtKjqT5MBN3tPB5sJmKj8G7ZtjWVA@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Mon, 18 Sept 2023 at 18:49, Jean-Marc Voillequin (MA)
<Jean-Marc(dot)Voillequin(at)moodys(dot)com> wrote:
> I know I can test the ROWCOUNT or the FOUND indicator, but it’s not 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 = PG_CONTEXT;
if split_part(ctx, E'\n', 2) = '' 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
From | Date | Subject | |
---|---|---|---|
Next Message | Jean-Marc Voillequin (MA) | 2023-09-18 14:05:24 | RE: no_data_found oracle vs pg |
Previous Message | Pavel Stehule | 2023-09-18 06:54:42 | Re: no_data_found oracle vs pg |