pgsql: Fix PL/pgSQL error message on EOF in the middle of an expression

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix PL/pgSQL error message on EOF in the middle of an expression
Date: 2026-10-31 11:01:03
Message-ID: E1xN6pb-00000001Wbd-0RGj@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix PL/pgSQL error message on EOF in the middle of an expression

read_sql_construct() takes up to three terminator tokens, passing zero
for those not used. But zero is also the token code for end of input,
so when the function body ended in the middle of an expression or
statement, the loop treated EOF as a valid terminator and stopped
there, instead of reaching the code that reports a missing terminator.
Users got a generic 'syntax error at end of input', or a misleading
'missing expression at end of input', instead of e.g. 'missing "THEN"
at end of SQL expression'.

Don't let unused terminator slots match EOF.

Author: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
Discussion: https://www.postgresql.org/message-id/CAM2+6=WcWycVx0j-zw=0jFJxfazFHtZadqZbBedEg2AQkGasfQ@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/46d7c16ca14e01211f75b39b4062a916dcb0c6b2

Modified Files
--------------
src/pl/plpgsql/src/expected/plpgsql_misc.out | 9 +++++++++
src/pl/plpgsql/src/pl_gram.y | 5 +++--
src/pl/plpgsql/src/sql/plpgsql_misc.sql | 4 ++++
3 files changed, 16 insertions(+), 2 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-10-31 11:47:29 pgsql: Fix two crashes on a concurrently dropped schema
Previous Message Robert Haas 2026-10-31 10:42:10 Re: pgsql: Set HEAP_XMAX_INVALID for tuples updated by aborted subtransacti