Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify COUNT() to output agtype #1311

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6503,6 +6503,115 @@ $$ ) AS (case_statement agtype);
{"id": 844424930131970, "label": "connected_to", "end_id": 281474976710660, "start_id": 281474976710659, "properties": {"k": 1, "id": 2}}::edge
(2 rows)

--CASE with count()
--count(*)
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN n, CASE n.j
WHEN 1 THEN count(*)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);
j | case_statement
------------------------------------------------------------------------------------------------+----------------
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex | "not count"
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex | "not count"
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex | "not count"
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex | 1
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex | "not count"
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex | "not count"
(6 rows)

--concatenated
SELECT * FROM cypher('case_statement', $$
MATCH (n) MATCH (m)
RETURN n, CASE n.j
WHEN 1 THEN count(*)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);
j | case_statement
------------------------------------------------------------------------------------------------+----------------
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex | "not count"
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex | "not count"
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex | "not count"
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex | 6
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex | "not count"
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex | "not count"
(6 rows)

--count(n)
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN n, CASE n.j
WHEN 1 THEN count(n)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);
j | case_statement
------------------------------------------------------------------------------------------------+----------------
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex | "not count"
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex | "not count"
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex | "not count"
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex | 1
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex | "not count"
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex | "not count"
(6 rows)

--concatenated
SELECT * FROM cypher('case_statement', $$
MATCH (n) MATCH (m)
RETURN n, CASE n.j
WHEN 1 THEN count(n)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);
j | case_statement
------------------------------------------------------------------------------------------------+----------------
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex | "not count"
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex | "not count"
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex | "not count"
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex | 6
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex | "not count"
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex | "not count"
(6 rows)

--count(1)
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN n, CASE n.j
WHEN 1 THEN count(1)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);
j | case_statement
------------------------------------------------------------------------------------------------+----------------
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex | "not count"
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex | "not count"
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex | "not count"
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex | 1
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex | "not count"
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex | "not count"
(6 rows)

--concatenated
SELECT * FROM cypher('case_statement', $$
MATCH (n) MATCH (m)
RETURN n, CASE n.j
WHEN 1 THEN count(1)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);
j | case_statement
------------------------------------------------------------------------------------------------+----------------
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex | "not count"
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex | "not count"
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex | "not count"
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex | 6
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex | "not count"
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex | "not count"
(6 rows)

-- RETURN * and (u)--(v) optional forms
SELECT create_graph('opt_forms');
NOTICE: graph "opt_forms" has been created
Expand Down
56 changes: 56 additions & 0 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,62 @@ SELECT * FROM cypher('case_statement', $$
END
$$ ) AS (case_statement agtype);

--CASE with count()

--count(*)
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN n, CASE n.j
WHEN 1 THEN count(*)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);

--concatenated
SELECT * FROM cypher('case_statement', $$
MATCH (n) MATCH (m)
RETURN n, CASE n.j
WHEN 1 THEN count(*)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);

--count(n)
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN n, CASE n.j
WHEN 1 THEN count(n)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);

--concatenated
SELECT * FROM cypher('case_statement', $$
MATCH (n) MATCH (m)
RETURN n, CASE n.j
WHEN 1 THEN count(n)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);

--count(1)
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN n, CASE n.j
WHEN 1 THEN count(1)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);

--concatenated
SELECT * FROM cypher('case_statement', $$
MATCH (n) MATCH (m)
RETURN n, CASE n.j
WHEN 1 THEN count(1)
ELSE 'not count'
END
$$ ) AS (j agtype, case_statement agtype);


-- RETURN * and (u)--(v) optional forms
SELECT create_graph('opt_forms');
Expand Down
Loading