pgsql: Add error_on_null(), checking if the input is the null value

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add error_on_null(), checking if the input is the null value
Date: 2025-10-22 00:59:20
Message-ID: E1vBNCC-002ryU-0S@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add error_on_null(), checking if the input is the null value

This polymorphic function produces an error if the input value is
detected as being the null value; otherwise it returns the input value
unchanged.

This function can for example become handy in SQL function bodies, to
enforce that exactly one row was returned.

Author: Joel Jacobson <joel(at)compiler(dot)org>
Reviewed-by: Vik Fearing <vik(at)postgresfriends(dot)org>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Discussion: https://postgr.es/m/ece8c6d1-2ab1-45d5-ba12-8dec96fc8886@app.fastmail.com
Discussion: https://postgr.es/m/de94808d-ed58-4536-9e28-e79b09a534c7@app.fastmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2b75c38b707a070922231de667a0bd08ee71b268

Modified Files
--------------
doc/src/sgml/func/func-comparison.sgml | 22 ++++++++++++++++++++
src/backend/utils/adt/misc.c | 14 +++++++++++++
src/include/catalog/pg_proc.dat | 3 +++
src/test/regress/expected/misc_functions.out | 31 ++++++++++++++++++++++++++++
src/test/regress/sql/misc_functions.sql | 11 ++++++++++
5 files changed, 81 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2025-10-22 01:11:19 pgsql: Bump catalog version for new function error_on_null()
Previous Message David Rowley 2025-10-21 22:36:49 pgsql: Use CompactAttribute more often, when possible