RE: no_data_found oracle vs pg

From: "Jean-Marc Voillequin (MA)" <Jean-Marc(dot)Voillequin(at)moodys(dot)com>
To: David Rowley <dgrowleyml(at)gmail(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 14:05:24
Message-ID: MN2PR20MB2735F1267E36D5C5A4E57BA8BEFBA@MN2PR20MB2735.namprd20.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks David,
It’s a very interesting idea.

From: David Rowley <dgrowleyml(at)gmail(dot)com>
Sent: Monday, September 18, 2023 3:14 PM
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
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(dot)Voillequin(at)moodys(dot)com<mailto: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

----------------------------------------------------------------------
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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Skelton, Adam J 2023-09-25 00:01:28 DDL in active production database
Previous Message David Rowley 2023-09-18 13:13:40 Re: no_data_found oracle vs pg