RE: no_data_found oracle vs pg - Mailing list pgsql-sql

From Jean-Marc Voillequin (MA)
Subject RE: no_data_found oracle vs pg
Date
Msg-id MN2PR20MB2735F1267E36D5C5A4E57BA8BEFBA@MN2PR20MB2735.namprd20.prod.outlook.com
Whole thread Raw
In response to Re: no_data_found oracle vs pg  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-sql

Thanks David,

It’s a very interesting idea.

 

From: David Rowley <dgrowleyml@gmail.com>
Sent: Monday, September 18, 2023 3:14 PM
To: Jean-Marc Voillequin (MA) <Jean-Marc.Voillequin@moodys.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-sql@postgresql.org
Subject: Re: no_data_found oracle vs pg

 

On Mon, 18 Sept 2023 at 18: 49, Jean-Marc Voillequin (MA) <Jean-Marc. Voillequin@ moodys. 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

ZjQcmQRYFpfptBannerStart

This email originated from outside of Moody's

Do not click links or open attachments unless you recognize the sender and know the content is safe.

ZjQcmQRYFpfptBannerEnd

On Mon, 18 Sept 2023 at 18:49, Jean-Marc Voillequin (MA)
<Jean-Marc.Voillequin@moodys.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

Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.

pgsql-sql by date:

Previous
From: David Rowley
Date:
Subject: Re: no_data_found oracle vs pg
Next
From: "Skelton, Adam J"
Date:
Subject: DDL in active production database