Skip to content

Commit 507a2e5

Browse files
gregfeliceclaude
andcommitted
Address Copilot round 3: reuse extract_iter_variable_name for list comprehensions
- Refactor build_list_comprehension_node() to reuse the shared extract_iter_variable_name() helper, so `var IN list` validation is consistent between list comprehensions and predicate functions (all/any/none/single). Qualified ColumnRefs like `x.y IN list` are now rejected in list comprehensions the same way they are in predicate functions. - Update list_comprehension expected output for the normalized lowercase "syntax error at or near IN" message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cc19476 commit 507a2e5

2 files changed

Lines changed: 13 additions & 20 deletions

File tree

regress/expected/list_comprehension.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,11 @@ LINE 1: ...$$ RETURN [i IN range(0, 10, 2) WHERE i>5 | i^2], i $$) AS (...
577577
HINT: variable i does not exist within scope of usage
578578
-- Invalid list comprehension
579579
SELECT * FROM cypher('list_comprehension', $$ RETURN [1 IN range(0, 10, 2) WHERE 2>5] $$) AS (result agtype);
580-
ERROR: Syntax error at or near IN
580+
ERROR: syntax error at or near IN
581581
LINE 1: SELECT * FROM cypher('list_comprehension', $$ RETURN [1 IN r...
582582
^
583583
SELECT * FROM cypher('list_comprehension', $$ RETURN [1 IN range(0, 10, 2) | 1] $$) AS (result agtype);
584-
ERROR: Syntax error at or near IN
584+
ERROR: syntax error at or near IN
585585
LINE 1: SELECT * FROM cypher('list_comprehension', $$ RETURN [1 IN r...
586586
^
587587
-- Issue - error using list comprehension with WITH *

src/backend/parser/cypher_gram.y

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,29 +3339,22 @@ static Node *build_list_comprehension_node(Node *var, Node *expr,
33393339
int location)
33403340
{
33413341
SubLink *sub;
3342-
String *val;
3343-
ColumnRef *cref = NULL;
3342+
ColumnRef *cref;
3343+
char *varname;
33443344
cypher_list_comprehension *list_comp = NULL;
33453345

3346-
if (!IsA(var, ColumnRef))
3347-
{
3348-
ereport(ERROR,
3349-
(errcode(ERRCODE_SYNTAX_ERROR),
3350-
errmsg("Syntax error at or near IN")));
3351-
}
3352-
3353-
cref = (ColumnRef *)var;
3354-
val = linitial(cref->fields);
3355-
if (!IsA(val, String))
3356-
{
3357-
ereport(ERROR,
3358-
(errcode(ERRCODE_SYNTAX_ERROR),
3359-
errmsg("Invalid list comprehension variable name")));
3360-
}
3346+
/*
3347+
* Reuse the shared iterator-name helper so list comprehensions and
3348+
* predicate functions (all/any/none/single) validate `var IN list`
3349+
* the same way — in particular, qualified ColumnRefs like `x.y` are
3350+
* rejected rather than silently treated as iterator `x`.
3351+
*/
3352+
varname = extract_iter_variable_name(var);
3353+
cref = (ColumnRef *) var;
33613354

33623355
/* build the list comprehension node */
33633356
list_comp = make_ag_node(cypher_list_comprehension);
3364-
list_comp->varname = val->sval;
3357+
list_comp->varname = varname;
33653358
list_comp->expr = expr;
33663359
list_comp->where = where;
33673360
list_comp->mapping_expr = (mapping_expr != NULL) ? mapping_expr :

0 commit comments

Comments
 (0)