Add PL/pgSQL extra check no_data_found - Mailing list pgsql-hackers

From Sergey Shinderuk
Subject Add PL/pgSQL extra check no_data_found
Date
Msg-id 799a9ffb-a74a-52da-8976-d89ad9b37129@postgrespro.ru
Whole thread Raw
Responses Re: Add PL/pgSQL extra check no_data_found  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
Hello,

I propose to add a new value "no_data_found" for the 
plpgsql.extra_errors and plpgsql.extra_warnings parameters [1].

With plpgsql.extra_errors=no_data_found SELECT INTO raises no_data_found 
exception when the result set is empty. With 
plpgsql.extra_errors=too_many_rows,no_data_found SELECT INTO behaves 
like SELECT INTO STRICT [2]. This could simplify migration from PL/SQL 
and may be just more convenient.

One potential downside is that plpgsql.extra_errors=no_data_found could 
break existing functions expecting to get null or checking IF found 
explicitly. This is also true for the too_many_rows exception, but 
arguably it's a programmer error, while no_data_found switches to a 
different convention for handling (or not handling) an empty result with 
SELECT INTO.

Otherwise the patch is straightforward.

What do you think?

-- 
Sergey Shinderuk        https://postgrespro.com/


[1] 
https://www.postgresql.org/docs/devel/plpgsql-development-tips.html#PLPGSQL-EXTRA-CHECKS
[2] 
https://www.postgresql.org/docs/devel/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW
Attachment

pgsql-hackers by date:

Previous
From: Melih Mutlu
Date:
Subject: Re: [PATCH] psql: Add tab-complete for optional view parameters
Next
From: Alvaro Herrera
Date:
Subject: Re: add \dpS to psql