pgsql: Fix ECPG's handling of type names that match SQL keywords.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix ECPG's handling of type names that match SQL keywords.
Date: 2022-07-12 21:05:56
Message-ID: E1oBN4t-002US0-5b@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix ECPG's handling of type names that match SQL keywords.

Previously, ECPG could only cope with variable declarations whose
type names either weren't any SQL keyword, or were at least partially
reserved. If you tried to use something in the unreserved_keyword
category, you got a syntax error.

This is pretty awful, not only because it says right on the tin that
those words are not reserved, but because the set of such keywords
tends to grow over time. Thus, an ECPG program that was just fine
last year could fail when recompiled with a newer SQL grammar.
We had to work around this recently when STRING became a keyword,
but it's time for an actual fix instead of a band-aid.

To fix, borrow a trick from C parsers and make the lexer's behavior
change when it sees a word that is known as a typedef. This is not
free of downsides: if you try to use such a name as a SQL keyword
in EXEC SQL later in the program, it won't be recognized as a SQL
keyword, leading to a syntax error there instead. So in a real
sense this is just trading one hazard for another. But there is an
important difference: with this, whether your ECPG program works
depends only on what typedef names and SQL commands are used in the
program text. If it compiles today it'll still compile next year,
even if more words have become SQL keywords.

Discussion: https://postgr.es/m/3661437.1653855582@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/83f1c7b742e80d5aa15e6710ecb324e388d007b3

Modified Files
--------------
doc/src/sgml/ecpg.sgml | 39 ++++-
src/interfaces/ecpg/preproc/ecpg.trailer | 170 ++++++++++++++-------
src/interfaces/ecpg/preproc/ecpg.type | 1 -
src/interfaces/ecpg/preproc/pgc.l | 17 ++-
src/interfaces/ecpg/preproc/preproc_extern.h | 2 +-
src/interfaces/ecpg/preproc/variable.c | 13 +-
src/interfaces/ecpg/test/expected/preproc-type.c | 56 ++++---
.../ecpg/test/expected/preproc-type.stderr | 36 ++---
src/interfaces/ecpg/test/preproc/type.pgc | 8 +-
9 files changed, 236 insertions(+), 106 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2022-07-13 01:02:27 Re: test_oat_hooks bug (was: Re: pgsql: Add copy/equal support for XID lists)
Previous Message Tom Lane 2022-07-12 20:30:52 pgsql: Invent qsort_interruptible().