From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix ECPG's handling of type names that match SQL keywords.
Date: Tue, 12 Jul 2022 21:05:56 +0000
Message-ID: <E1oBN4t-002US0-5b@gemulon.postgresql.org> (raw)
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(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Fix ECPG's handling of type names that match SQL keywords.
In-Reply-To: <E1oBN4t-002US0-5b@gemulon.postgresql.org>
References: <E1oBN4t-002US0-5b@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox