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 <[email protected]>
Discussion: 
https://www.postgresql.org/message-id/CAM2+6=WcWycVx0j-zw=0jfjxfazfhtzadqzbbedeg2aqkga...@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(-)

Reply via email to