diff --git a/regress/expected/expr.out b/regress/expected/expr.out index 2357f9f66..9d5c5aa11 100644 --- a/regress/expected/expr.out +++ b/regress/expected/expr.out @@ -6245,32 +6245,22 @@ NOTICE: graph "case_statement" has been created (1 row) -SELECT * FROM cypher('case_statement', $$CREATE ({i: 1, j: null})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 1, i: 1, j: null})-[:connected_to {id: 1, k:0}]->({id: 2, i: 'a', j: 'b'})$$) AS (result agtype); result -------- (0 rows) -SELECT * FROM cypher('case_statement', $$CREATE ({i: 'a', j: 'b'})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 3, i: 0, j: 1})-[:connected_to {id: 2, k:1}]->({id: 4, i: true, j: false})$$) AS (result agtype); result -------- (0 rows) -SELECT * FROM cypher('case_statement', $$CREATE ({i: 0, j: 1})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 5, i: [], j: [0,1,2]})$$) AS (result agtype); result -------- (0 rows) -SELECT * FROM cypher('case_statement', $$CREATE ({i: true, j: false})$$) AS (result agtype); - result --------- -(0 rows) - -SELECT * FROM cypher('case_statement', $$CREATE ({i: [], j: [0,1,2]})$$) AS (result agtype); - result --------- -(0 rows) - -SELECT * FROM cypher('case_statement', $$CREATE ({i: {}, j: {i:1}})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 6, i: {}, j: {i:1}})$$) AS (result agtype); result -------- (0 rows) @@ -6355,6 +6345,57 @@ $$ ) AS (j agtype, case_statement agtype); {"i": 1} | {"i": 1} (6 rows) +--CASE agtype_vertex WHEN value THEN result END +SELECT * FROM cypher('case_statement', $$ + MATCH (n) + RETURN CASE n + WHEN null THEN 'should not return me' + WHEN 'agtype_string' THEN 'wrong' + WHEN n THEN n + ELSE 'no n' + END +$$ ) AS (case_statement agtype); + case_statement +------------------------------------------------------------------------------------------------ + {"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex + {"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex + {"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex + {"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex + {"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex + {"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex +(6 rows) + +--CASE with match and edges +SELECT * FROM cypher('case_statement', $$ + MATCH (n)-[e]->(m) + RETURN CASE + WHEN null THEN 'should not return me' + WHEN n.i = 1 THEN n + WHEN n.i = 0 THEN m + ELSE 'none' + END +$$ ) AS (case_statement agtype); + case_statement +---------------------------------------------------------------------------------------------- + {"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex + {"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex +(2 rows) + +SELECT * FROM cypher('case_statement', $$ + MATCH (n)-[e]->(m) + RETURN CASE + WHEN null THEN 'should not return me' + WHEN e.k = 1 THEN e + WHEN e.k = 0 THEN e + ELSE 'none' + END +$$ ) AS (case_statement agtype); + case_statement +------------------------------------------------------------------------------------------------------------------------------------------------- + {"id": 844424930131969, "label": "connected_to", "end_id": 281474976710658, "start_id": 281474976710657, "properties": {"k": 0, "id": 1}}::edge + {"id": 844424930131970, "label": "connected_to", "end_id": 281474976710660, "start_id": 281474976710659, "properties": {"k": 1, "id": 2}}::edge +(2 rows) + -- RETURN * and (u)--(v) optional forms SELECT create_graph('opt_forms'); NOTICE: graph "opt_forms" has been created @@ -7213,9 +7254,10 @@ NOTICE: graph "VLE" has been dropped (1 row) SELECT * FROM drop_graph('case_statement', true); -NOTICE: drop cascades to 2 other objects +NOTICE: drop cascades to 3 other objects DETAIL: drop cascades to table case_statement._ag_label_vertex drop cascades to table case_statement._ag_label_edge +drop cascades to table case_statement.connected_to NOTICE: graph "case_statement" has been dropped drop_graph ------------ diff --git a/regress/sql/expr.sql b/regress/sql/expr.sql index ea6a795c5..c566ef573 100644 --- a/regress/sql/expr.sql +++ b/regress/sql/expr.sql @@ -2595,12 +2595,10 @@ $$) AS (i agtype); --CASE SELECT create_graph('case_statement'); -SELECT * FROM cypher('case_statement', $$CREATE ({i: 1, j: null})$$) AS (result agtype); -SELECT * FROM cypher('case_statement', $$CREATE ({i: 'a', j: 'b'})$$) AS (result agtype); -SELECT * FROM cypher('case_statement', $$CREATE ({i: 0, j: 1})$$) AS (result agtype); -SELECT * FROM cypher('case_statement', $$CREATE ({i: true, j: false})$$) AS (result agtype); -SELECT * FROM cypher('case_statement', $$CREATE ({i: [], j: [0,1,2]})$$) AS (result agtype); -SELECT * FROM cypher('case_statement', $$CREATE ({i: {}, j: {i:1}})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 1, i: 1, j: null})-[:connected_to {id: 1, k:0}]->({id: 2, i: 'a', j: 'b'})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 3, i: 0, j: 1})-[:connected_to {id: 2, k:1}]->({id: 4, i: true, j: false})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 5, i: [], j: [0,1,2]})$$) AS (result agtype); +SELECT * FROM cypher('case_statement', $$CREATE ({id: 6, i: {}, j: {i:1}})$$) AS (result agtype); --standalone case & edge cases --base case @@ -2646,6 +2644,39 @@ SELECT * FROM cypher('case_statement', $$ END $$ ) AS (j agtype, case_statement agtype); +--CASE agtype_vertex WHEN value THEN result END +SELECT * FROM cypher('case_statement', $$ + MATCH (n) + RETURN CASE n + WHEN null THEN 'should not return me' + WHEN 'agtype_string' THEN 'wrong' + WHEN n THEN n + ELSE 'no n' + END +$$ ) AS (case_statement agtype); + +--CASE with match and edges +SELECT * FROM cypher('case_statement', $$ + MATCH (n)-[e]->(m) + RETURN CASE + WHEN null THEN 'should not return me' + WHEN n.i = 1 THEN n + WHEN n.i = 0 THEN m + ELSE 'none' + END +$$ ) AS (case_statement agtype); + +SELECT * FROM cypher('case_statement', $$ + MATCH (n)-[e]->(m) + RETURN CASE + WHEN null THEN 'should not return me' + WHEN e.k = 1 THEN e + WHEN e.k = 0 THEN e + ELSE 'none' + END +$$ ) AS (case_statement agtype); + + -- RETURN * and (u)--(v) optional forms SELECT create_graph('opt_forms'); SELECT * FROM cypher('opt_forms', $$CREATE ({i:1})-[:KNOWS]->({i:2})<-[:KNOWS]-({i:3})$$)AS (result agtype);