Skip to content

Commit ab2b199

Browse files
committed
Adjust 'could not find rte for' ERROR message
Adjusted the following type of error message. It was mentioned in issue 2263 as being incorrect, which it isn't. However, it did need some clarification added - ERROR: could not find rte for <column name> Added a HINT for additional clarity - HINT: variable <column name> does not exist within scope of usage For example: CREATE p0=(n0), (n1{k:EXISTS{WITH p0}}) RETURN 1 ERROR: could not find rte for p0 LINE 3: CREATE p0=(n0), (n1{k:EXISTS{WITH p0}}) ^ HINT: variable p0 does not exist within scope of usage Additionally, added pstate->p_expr_kind == EXPR_KIND_INSERT_TARGET to transform_cypher_clause_as_subquery. Updated existing regression tests. Added regression tests from issue. modified: regress/expected/cypher_call.out modified: regress/expected/cypher_subquery.out modified: regress/expected/cypher_union.out modified: regress/expected/cypher_with.out modified: regress/expected/expr.out modified: regress/expected/list_comprehension.out modified: regress/expected/scan.out modified: src/backend/parser/cypher_clause.c modified: src/backend/parser/cypher_expr.c
1 parent 5aed9ec commit ab2b199

File tree

10 files changed

+118
-3
lines changed

10 files changed

+118
-3
lines changed

regress/expected/cypher_call.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ SELECT * FROM cypher('cypher_call', $$CALL sqrt(64) YIELD sqrt WHERE a = 8 RETUR
125125
ERROR: could not find rte for a
126126
LINE 2: ...r('cypher_call', $$CALL sqrt(64) YIELD sqrt WHERE a = 8 RETU...
127127
^
128+
HINT: variable a does not exist within scope of usage
128129
/* MATCH CALL RETURN, should fail */
129130
SELECT * FROM cypher('cypher_call', $$ MATCH (a) CALL sqrt(64) RETURN sqrt $$) as (sqrt agtype);
130131
ERROR: Procedure call inside a query does not support naming results implicitly
@@ -171,6 +172,7 @@ SELECT * FROM cypher('cypher_call', $$ MATCH (a) CALL sqrt(64) YIELD sqrt WHERE
171172
ERROR: could not find rte for b
172173
LINE 1: ...all', $$ MATCH (a) CALL sqrt(64) YIELD sqrt WHERE b = 8 RETU...
173174
^
175+
HINT: variable b does not exist within scope of usage
174176
/* CALL MATCH YIELD WHERE UPDATE/RETURN */
175177
SELECT * FROM cypher('cypher_call', $$ CALL sqrt(64) YIELD sqrt WHERE sqrt > 1 CREATE ({n:'c'}) $$) as (a agtype);
176178
a

regress/expected/cypher_subquery.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ SELECT * FROM cypher('subquery', $$ MATCH (a:person)
135135
ERROR: could not find rte for c
136136
LINE 5: RETURN c
137137
^
138+
HINT: variable c does not exist within scope of usage
138139
--union, no returns
139140
SELECT * FROM cypher('subquery', $$ MATCH (a:person)
140141
WHERE EXISTS {
@@ -341,6 +342,7 @@ SELECT * FROM cypher('subquery', $$ RETURN 1,
341342
ERROR: could not find rte for a
342343
LINE 4: RETURN a
343344
^
345+
HINT: variable a does not exist within scope of usage
344346
--- COUNT
345347
--count pattern subquery in where
346348
SELECT * FROM cypher('subquery', $$ MATCH (a:person)
@@ -540,6 +542,7 @@ SELECT * FROM cypher('subquery', $$ MATCH (a:person)
540542
ERROR: could not find rte for b
541543
LINE 2: RETURN a.name, COUNT{MATCH (a) RETURN b} $$)
542544
^
545+
HINT: variable b does not exist within scope of usage
543546
--incorrect nested variable reference
544547
SELECT * FROM cypher('subquery', $$ MATCH (a:person)
545548
RETURN a.name, COUNT{MATCH (a)
@@ -549,6 +552,7 @@ SELECT * FROM cypher('subquery', $$ MATCH (a:person)
549552
ERROR: could not find rte for b
550553
LINE 4: RETURN b} $$)
551554
^
555+
HINT: variable b does not exist within scope of usage
552556
--count nested with exists
553557
SELECT * FROM cypher('subquery', $$ MATCH (a:person)
554558
RETURN a.name,

regress/expected/cypher_union.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ SELECT * FROM cypher('cypher_union', $$MATCH (n) RETURN n UNION ALL MATCH (m) RE
141141
ERROR: could not find rte for n
142142
LINE 2: ..., $$MATCH (n) RETURN n UNION ALL MATCH (m) RETURN n$$) AS (r...
143143
^
144+
HINT: variable n does not exist within scope of usage
144145
/*
145146
*UNION and UNION ALL, type casting
146147
*/

regress/expected/cypher_with.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ $$) AS (a agtype, b agtype);
267267
ERROR: could not find rte for b
268268
LINE 4: RETURN m,b
269269
^
270+
HINT: variable b does not exist within scope of usage
270271
SELECT * FROM cypher('cypher_with', $$
271272
MATCH (m)-[]->(b)
272273
WITH m AS start_node,b AS end_node
@@ -278,6 +279,7 @@ $$) AS (id agtype, node agtype);
278279
ERROR: could not find rte for end_node
279280
LINE 7: RETURN id(start_node),end_node.name
280281
^
282+
HINT: variable end_node does not exist within scope of usage
281283
-- Clean up
282284
SELECT drop_graph('cypher_with', true);
283285
NOTICE: drop cascades to 4 other objects
@@ -320,6 +322,7 @@ $$) AS (n agtype, d agtype);
320322
ERROR: could not find rte for d
321323
LINE 8: RETURN c,d
322324
^
325+
HINT: variable d does not exist within scope of usage
323326
-- Issue 396 (should error out)
324327
SELECT * FROM cypher('graph',$$
325328
CREATE (v),(u),(w),
@@ -338,6 +341,7 @@ $$) as (a agtype,b agtype);
338341
ERROR: could not find rte for v
339342
LINE 4: RETURN v,path_length
340343
^
344+
HINT: variable v does not exist within scope of usage
341345
-- Clean up
342346
SELECT drop_graph('graph', true);
343347
NOTICE: drop cascades to 6 other objects

regress/expected/expr.out

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,6 +3370,7 @@ $$) AS (toBooleanList agtype);
33703370
ERROR: could not find rte for fail
33713371
LINE 2: RETURN toBooleanList(fail)
33723372
^
3373+
HINT: variable fail does not exist within scope of usage
33733374
SELECT * FROM cypher('expr', $$
33743375
RETURN toBooleanList("fail")
33753376
$$) AS (toBooleanList agtype);
@@ -3513,6 +3514,7 @@ $$) AS (toFloatList agtype);
35133514
ERROR: could not find rte for failed
35143515
LINE 2: RETURN toFloatList([failed])
35153516
^
3517+
HINT: variable failed does not exist within scope of usage
35163518
SELECT * FROM cypher('expr', $$
35173519
RETURN toFloatList("failed")
35183520
$$) AS (toFloatList agtype);
@@ -3892,12 +3894,14 @@ $$) AS (toStringList agtype);
38923894
ERROR: could not find rte for b
38933895
LINE 2: RETURN toStringList([['a', b]])
38943896
^
3897+
HINT: variable b does not exist within scope of usage
38953898
SELECT * FROM cypher('expr', $$
38963899
RETURN toStringList([test])
38973900
$$) AS (toStringList agtype);
38983901
ERROR: could not find rte for test
38993902
LINE 2: RETURN toStringList([test])
39003903
^
3904+
HINT: variable test does not exist within scope of usage
39013905
--
39023906
-- reverse(string)
39033907
--
@@ -7923,6 +7927,7 @@ SELECT * FROM cypher('list', $$ RETURN tail(abc) $$) AS (tail agtype);
79237927
ERROR: could not find rte for abc
79247928
LINE 1: SELECT * FROM cypher('list', $$ RETURN tail(abc) $$) AS (tai...
79257929
^
7930+
HINT: variable abc does not exist within scope of usage
79267931
SELECT * FROM cypher('list', $$ RETURN tail() $$) AS (tail agtype);
79277932
ERROR: function ag_catalog.age_tail() does not exist
79287933
LINE 1: SELECT * FROM cypher('list', $$ RETURN tail() $$) AS (tail a...
@@ -9011,9 +9016,70 @@ SELECT agtype_hash_cmp(agtype_in('[null, null, null, null, null]'));
90119016
-505290721
90129017
(1 row)
90139018

9019+
--
9020+
-- Issue 2263: AGE returns incorrect error message for EXISTS subquery outer variable reference
9021+
--
9022+
-- NOTE: There isn't really anything incorrect about the message. However,
9023+
-- it could be more clear.
9024+
--
9025+
SELECT * FROM create_graph('issue_2263');
9026+
NOTICE: graph "issue_2263" has been created
9027+
create_graph
9028+
--------------
9029+
9030+
(1 row)
9031+
9032+
SELECT * FROM cypher('issue_2263', $$
9033+
CREATE a=()-[:T]->(), p=({k:exists{return a}})-[:T]->()
9034+
RETURN 1
9035+
$$) AS (one agtype);
9036+
ERROR: could not find rte for a
9037+
LINE 2: CREATE a=()-[:T]->(), p=({k:exists{return a}})-[:T]->()
9038+
^
9039+
HINT: variable a does not exist within scope of usage
9040+
SELECT * FROM cypher('issue_2263', $$
9041+
CREATE p0=(n0), (n1{k:EXISTS{WITH p0}})
9042+
RETURN 1
9043+
$$) AS (one agtype);
9044+
ERROR: could not find rte for p0
9045+
LINE 2: CREATE p0=(n0), (n1{k:EXISTS{WITH p0}})
9046+
^
9047+
HINT: variable p0 does not exist within scope of usage
9048+
SELECT * FROM cypher('issue_2263', $$
9049+
CREATE ()-[r4 :T6]->(), ({k2:COUNT{WITH r4.k AS a3 UNWIND [] AS a4 WITH DISTINCT NULL AS a5}})
9050+
RETURN 1
9051+
$$) AS (one agtype);
9052+
ERROR: could not find rte for r4
9053+
LINE 2: CREATE ()-[r4 :T6]->(), ({k2:COUNT{WITH r4.k AS a3 UNWIN...
9054+
^
9055+
HINT: variable r4 does not exist within scope of usage
9056+
SELECT * FROM cypher('issue_2263', $$
9057+
CREATE (x), ({a1:EXISTS { RETURN COUNT(0) AS a2, keys(x) AS a4 }})
9058+
$$) AS (out agtype);
9059+
ERROR: could not find rte for x
9060+
LINE 2: ...TE (x), ({a1:EXISTS { RETURN COUNT(0) AS a2, keys(x) AS a4 }...
9061+
^
9062+
HINT: variable x does not exist within scope of usage
9063+
SELECT * FROM cypher('issue_2263', $$
9064+
CREATE x = (), ({ a0:COUNT { MATCH () WHERE CASE WHEN true THEN (x IS NULL) END RETURN 0 } })
9065+
$$) AS (out agtype);
9066+
ERROR: could not find rte for x
9067+
LINE 2: ...({ a0:COUNT { MATCH () WHERE CASE WHEN true THEN (x IS NULL)...
9068+
^
9069+
HINT: variable x does not exist within scope of usage
90149070
--
90159071
-- Cleanup
90169072
--
9073+
SELECT * FROM drop_graph('issue_2263', true);
9074+
NOTICE: drop cascades to 2 other objects
9075+
DETAIL: drop cascades to table issue_2263._ag_label_vertex
9076+
drop cascades to table issue_2263._ag_label_edge
9077+
NOTICE: graph "issue_2263" has been dropped
9078+
drop_graph
9079+
------------
9080+
9081+
(1 row)
9082+
90179083
SELECT * FROM drop_graph('issue_1988', true);
90189084
NOTICE: drop cascades to 4 other objects
90199085
DETAIL: drop cascades to table issue_1988._ag_label_vertex

regress/expected/list_comprehension.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,12 @@ SELECT * FROM cypher('list_comprehension', $$ RETURN [i IN range(0, 10, 2)],i $$
569569
ERROR: could not find rte for i
570570
LINE 1: ..._comprehension', $$ RETURN [i IN range(0, 10, 2)],i $$) AS (...
571571
^
572+
HINT: variable i does not exist within scope of usage
572573
SELECT * FROM cypher('list_comprehension', $$ RETURN [i IN range(0, 10, 2) WHERE i>5 | i^2], i $$) AS (result agtype, i agtype);
573574
ERROR: could not find rte for i
574575
LINE 1: ...$$ RETURN [i IN range(0, 10, 2) WHERE i>5 | i^2], i $$) AS (...
575576
^
577+
HINT: variable i does not exist within scope of usage
576578
-- Invalid list comprehension
577579
SELECT * FROM cypher('list_comprehension', $$ RETURN [1 IN range(0, 10, 2) WHERE 2>5] $$) AS (result agtype);
578580
ERROR: Syntax error at or near IN

regress/expected/scan.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,36 +437,42 @@ $$) AS t(id text);
437437
ERROR: could not find rte for _$09A_z
438438
LINE 2: RETURN _$09A_z
439439
^
440+
HINT: variable _$09A_z does not exist within scope of usage
440441
SELECT * FROM cypher('scan', $$
441442
RETURN A
442443
$$) AS t(id text);
443444
ERROR: could not find rte for A
444445
LINE 2: RETURN A
445446
^
447+
HINT: variable A does not exist within scope of usage
446448
SELECT * FROM cypher('scan', $$
447449
RETURN z
448450
$$) AS t(id text);
449451
ERROR: could not find rte for z
450452
LINE 2: RETURN z
451453
^
454+
HINT: variable z does not exist within scope of usage
452455
SELECT * FROM cypher('scan', $$
453456
RETURN `$`
454457
$$) AS t(id text);
455458
ERROR: could not find rte for $
456459
LINE 2: RETURN `$`
457460
^
461+
HINT: variable $ does not exist within scope of usage
458462
SELECT * FROM cypher('scan', $$
459463
RETURN `0`
460464
$$) AS t(id text);
461465
ERROR: could not find rte for 0
462466
LINE 2: RETURN `0`
463467
^
468+
HINT: variable 0 does not exist within scope of usage
464469
SELECT * FROM cypher('scan', $$
465470
RETURN ````
466471
$$) AS t(id text);
467472
ERROR: could not find rte for `
468473
LINE 2: RETURN ````
469474
^
475+
HINT: variable ` does not exist within scope of usage
470476
-- zero-length quoted identifier
471477
SELECT * FROM cypher('scan', $$
472478
RETURN ``

regress/sql/expr.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,9 +3634,36 @@ SELECT * FROM cypher('issue_1988', $$
36343634
SELECT agtype_access_operator(agtype_in('[null, null]'));
36353635
SELECT agtype_hash_cmp(agtype_in('[null, null, null, null, null]'));
36363636

3637+
--
3638+
-- Issue 2263: AGE returns incorrect error message for EXISTS subquery outer variable reference
3639+
--
3640+
-- NOTE: There isn't really anything incorrect about the message. However,
3641+
-- it could be more clear.
3642+
--
3643+
SELECT * FROM create_graph('issue_2263');
3644+
SELECT * FROM cypher('issue_2263', $$
3645+
CREATE a=()-[:T]->(), p=({k:exists{return a}})-[:T]->()
3646+
RETURN 1
3647+
$$) AS (one agtype);
3648+
SELECT * FROM cypher('issue_2263', $$
3649+
CREATE p0=(n0), (n1{k:EXISTS{WITH p0}})
3650+
RETURN 1
3651+
$$) AS (one agtype);
3652+
SELECT * FROM cypher('issue_2263', $$
3653+
CREATE ()-[r4 :T6]->(), ({k2:COUNT{WITH r4.k AS a3 UNWIND [] AS a4 WITH DISTINCT NULL AS a5}})
3654+
RETURN 1
3655+
$$) AS (one agtype);
3656+
SELECT * FROM cypher('issue_2263', $$
3657+
CREATE (x), ({a1:EXISTS { RETURN COUNT(0) AS a2, keys(x) AS a4 }})
3658+
$$) AS (out agtype);
3659+
SELECT * FROM cypher('issue_2263', $$
3660+
CREATE x = (), ({ a0:COUNT { MATCH () WHERE CASE WHEN true THEN (x IS NULL) END RETURN 0 } })
3661+
$$) AS (out agtype);
3662+
36373663
--
36383664
-- Cleanup
36393665
--
3666+
SELECT * FROM drop_graph('issue_2263', true);
36403667
SELECT * FROM drop_graph('issue_1988', true);
36413668
SELECT * FROM drop_graph('issue_1953', true);
36423669
SELECT * FROM drop_graph('expanded_map', true);

src/backend/parser/cypher_clause.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6315,6 +6315,7 @@ transform_cypher_clause_as_subquery(cypher_parsestate *cpstate,
63156315
pstate->p_expr_kind == EXPR_KIND_OTHER ||
63166316
pstate->p_expr_kind == EXPR_KIND_WHERE ||
63176317
pstate->p_expr_kind == EXPR_KIND_SELECT_TARGET ||
6318+
pstate->p_expr_kind == EXPR_KIND_INSERT_TARGET ||
63186319
pstate->p_expr_kind == EXPR_KIND_FROM_SUBSELECT);
63196320

63206321
/*

src/backend/parser/cypher_expr.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,11 @@ static Node *transform_ColumnRef(cypher_parsestate *cpstate, ColumnRef *cref)
423423
else
424424
{
425425
ereport(ERROR,
426-
(errcode(ERRCODE_UNDEFINED_COLUMN),
427-
errmsg("could not find rte for %s", colname),
428-
parser_errposition(pstate, cref->location)));
426+
(errcode(ERRCODE_UNDEFINED_COLUMN),
427+
errmsg("could not find rte for %s", colname),
428+
errhint("variable %s does not exist within scope of usage",
429+
colname),
430+
parser_errposition(pstate, cref->location)));
429431
}
430432

431433
if (node == NULL)

0 commit comments

Comments
 (0)