pgsql: plpgsql: make WHEN OTHERS distinct from WHEN SQLSTATE '00000'.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: plpgsql: make WHEN OTHERS distinct from WHEN SQLSTATE '00000'.
Date: 2025-03-22 18:17:07
Message-ID: E1tw3P8-000UhQ-1n@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

plpgsql: make WHEN OTHERS distinct from WHEN SQLSTATE '00000'.

The catchall exception condition OTHERS was represented as
sqlerrstate == 0, which was a poor choice because that comes
out the same as SQLSTATE '00000'. While we don't issue that
as an error code ourselves, there isn't anything particularly
stopping users from doing so. Use -1 instead, which can't
match any allowed SQLSTATE string.

While at it, invent a macro PLPGSQL_OTHERS to use instead of
a hard-coded magic number.

While this seems like a bug fix, I'm inclined not to back-patch.
It seems barely possible that someone has written code like this
and would be annoyed by changing the behavior in a minor release.

Reported-by: David Fiedler <david(dot)fido(dot)fiedler(at)gmail(dot)com>
Author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/CAHjN70-=H5EpTOuZVbC8mPvRS5EfZ4MY2=OUdVDWoyGvKhb+Rw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/58fdca2204de5f683f025df37553e5e69cb6adb1

Modified Files
--------------
src/pl/plpgsql/src/pl_comp.c | 6 +-----
src/pl/plpgsql/src/pl_exec.c | 2 +-
src/pl/plpgsql/src/plpgsql.h | 5 ++++-
3 files changed, 6 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2025-03-22 22:10:35 pgsql: aio: Change prefix of PgAioResultStatus values to PGAIO_RS_
Previous Message Peter Geoghegan 2025-03-22 17:02:36 pgsql: Improve nbtree array primitive scan scheduling.