uesleilima opened a new pull request, #2373:
URL: https://github.com/apache/age/pull/2373
## Summary
Fix `execCypher()` crashing when column aliases are PostgreSQL reserved
words (#2370).
### Problem
The `buildCypher()` function generates SQL like:
```sql
SELECT * FROM cypher(NULL,NULL) AS (count agtype);
```
When the column alias is a reserved word (`count`, `order`, `type`, `group`,
`select`, etc.), PostgreSQL raises a parse error because the identifier is
unquoted.
This commonly happens when Cypher `RETURN` clauses use aggregation functions:
```python
cursor = age.execCypher(conn, "test_graph",
"MATCH (n:TestNode) RETURN count(n)",
cols=["count"]) # crashes
```
### Fix
Always double-quote column names in `_validate_column()`:
```python
# Before
return f"{name} {type_name}" # count agtype → ERROR
# After
return f'"{name}" {type_name}' # "count" agtype → OK
```
PostgreSQL always accepts double-quoted identifiers, so quoting
unconditionally is safe for all names — no reserved word list needed. This is
simpler and more maintainable than checking against a list of 60+ reserved
words.
Generated SQL after fix:
```sql
SELECT * FROM cypher(NULL,NULL) AS ("count" agtype);
```
## Tests
Added 11 new unit tests in `TestBuildCypher` class (no DB required):
- Simple column, column with type, multiple columns
- Reserved words: `count`, `order`, `type`, `select`, `group`
- Default column quoting
- Invalid column rejection
- `_validate_column()` direct quoting verification
## Closes
- Closes #2370
--
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]