gregfelice commented on code in PR #2359:
URL: https://github.com/apache/age/pull/2359#discussion_r3089613423
##########
src/backend/parser/cypher_gram.y:
##########
@@ -3268,6 +3295,44 @@ static cypher_relationship *build_VLE_relation(List
*left_arg,
return cr;
}
+/*
+ * Extract and validate the iterator variable name from a ColumnRef node.
+ * Used by predicate functions (all/any/none/single) which share the
+ * "variable IN list" syntax with list comprehensions.
+ */
+static char *extract_iter_variable_name(Node *var)
+{
+ ColumnRef *cref;
+ String *val;
+
+ if (!IsA(var, ColumnRef))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("syntax error at or near IN")));
+ }
+
+ cref = (ColumnRef *)var;
+
+ /* The iterator must be a simple unqualified name (single field) */
+ if (list_length(cref->fields) != 1)
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("qualified name not allowed as iterator variable")));
+ }
+
+ val = linitial(cref->fields);
+ if (!IsA(val, String))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("invalid iterator variable name")));
+ }
+
+ return val->sval;
+}
+
/* helper function to build a list_comprehension grammar node */
static Node *build_list_comprehension_node(Node *var, Node *expr,
Node *where, Node *mapping_expr,
Review Comment:
Addressed in commit 507a2e53. `build_list_comprehension_node()` now calls
`extract_iter_variable_name()` directly (cypher_gram.y:3352), so
iterator-variable validation — including rejection of qualified ColumnRefs like
`x.y IN list` — is shared between list comprehensions and predicate functions.
The `list_comprehension` regression expected output was updated to the
normalized lowercase error message.
--
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]