crprashant commented on issue #2355:
URL: https://github.com/apache/age/issues/2355#issuecomment-4330043160

   Hi @rafsun42 — I have a fix up for this in **#2415**.
   
   **TL;DR:** added a new `var_name_alias` non-terminal in `cypher_gram.y` that 
is used only at the three alias-binding sites (`RETURN ... AS x`, `WITH ... AS 
x` / `YIELD ... AS x`, `UNWIND ... AS x`). On top of plain identifiers it 
accepts the existing `safe_keywords` set, so all 49 non-conflicting reserved 
keywords (`count`, `exists`, `coalesce`, `match`, `return`, `where`, `order`, 
`limit`, `distinct`, `optional`, `detach`, `contains`, `starts`, `ends`, `in`, 
`is`, `not`, ...) are now valid aliases.
   
   **Your exact reproducer:**
   
   ```sql
   SELECT * FROM cypher('graph_name', $$ RETURN 1 AS count $$) as (a agtype);
   ```
   
   now returns `1` instead of `syntax error at or near "count"`.
   
   **Why scoped to alias positions only?** Extending `var_name` everywhere (so 
e.g. `MATCH (count)` would also work) is what one would intuitively try first — 
but bison rejected it with **156 shift/reduce conflicts**, because keyword 
tokens collide with their syntactic roles inside expressions and patterns. 
Restricting the broadening to `AS`-bound positions is conflict-free.
   
   **Boundaries (intentional):**
   - `END` / `NULL` / `TRUE` / `FALSE` (`conflicted_keywords`) remain rejected 
as aliases — they create real ambiguity with literal/CASE productions.
   - Pattern-variable positions like `MATCH (count)` are unchanged.
   - Reading a keyword-named alias back (`WITH 1 AS count RETURN count`) still 
fails because `expr_var` reads through `var_name`; widening that re-introduces 
the 156 conflicts. The literal repro from this issue is fully resolved; the 
read-back path would be a deeper grammar refactor and is out of scope here.
   
   **Verification:**
   - Clean PG18 build, no new bison conflicts.
   - `make installcheck` on PostgreSQL 18: 32/34 tests pass including the new 
`issue_2355` regression test (the only remaining failure, `age_upgrade`, is 
pre-existing on `master` and unrelated).
   - Fix is parser-only and PG-version-agnostic. (Note: `master` currently 
doesn't build on PG 16 for unrelated reasons — `cypher_set.c` / `age.c` use 
PG18-only APIs — so I couldn't reproduce against your AGE 1.16.0 / PG 16.13 
environment, but the patch lives entirely in `cypher_gram.y` and applies 
cleanly there.)
   
   The new regression test (`regress/sql/issue_2355.sql`) covers your exact 
reproducer plus 18 representative safe_keywords across `RETURN` / `WITH` / 
`UNWIND`, multiple keyword aliases in one projection, and explicit negative 
tests for the conflicted_keywords and pattern-position cases.
   
   Reviews welcome on #2415.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to