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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix ECPG's handling of type names that match SQL keywords.
Дата
Msg-id E1oBN4t-002US0-5b@gemulon.postgresql.org
обсуждение исходный текст
Список 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(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Invent qsort_interruptible().
Следующее
От: David Rowley
Дата:
Сообщение: pgsql: Tidy up code in get_cheapest_group_keys_order()