diff --git a/pages/pgql-2.0-spec.md b/pages/pgql-2.0-spec.md index b9aa3b43..1b5ceb09 100644 --- a/pages/pgql-2.0-spec.md +++ b/pages/pgql-2.0-spec.md @@ -1409,31 +1409,31 @@ For example:
-SELECT *
+SELECT *
FROM GRAPH_TABLE (financial_transactions
MATCH(n)
- COLUMNS(VERTEX_ID(n) as n_id, n.*))
+ COLUMNS(n.*))
ORDER BY "number", "name"
-SELECT ID(n), n.*
+SELECT n.*
FROM MATCH (n) ON financial_transactions
ORDER BY "number", "name"
-SELECT ID(n), n.*
+SELECT n.*
FROM MATCH (n:Person) ON financial_transactions
ORDER BY "name"
-SELECT *
-FROM GRAPH_TABLE(financial_transactions
- MATCH (a IS Account) (-[e IS transaction]-> COST e.amount)* (b IS Account)
- KEEP ANY CHEAPEST
- WHERE a.number = 10039 AND b.number = 2090
- COLUMNS(COUNT(EDGE_ID(e)) AS num_hops,
- SUM(e.amount) AS total_amount,
- ARRAY_AGG(e.amount) AS amounts_along_path))
-
-SELECT COUNT(e) AS num_hops
- , SUM(e.amount) AS total_amount
- , ARRAY_AGG(e.amount) AS amounts_along_path
-FROM MATCH ANY CHEAPEST (a:Account) (-[e:transaction]-> COST e.amount)* (b:Account)
- ON financial_transactions
-WHERE a.number = 10039 AND b.number = 2090
-
-SELECT *
-FROM GRAPH_TABLE(financial_transactions
- MATCH (a IS Account) (-[e IS transaction]- COST e.amount)* (b IS Account)
- KEEP ANY CHEAPEST
- WHERE a.number = 10039 AND b.number = 2090
- COLUMNS(COUNT(EDGE_ID(e)) AS num_hops
- , SUM(e.amount) AS total_amount
- , ARRAY_AGG(e.amount) AS amounts_along_path))
-
-SELECT COUNT(e) AS num_hops
- , SUM(e.amount) AS total_amount
- , ARRAY_AGG(e.amount) AS amounts_along_path
-FROM MATCH ANY CHEAPEST (a:Account) (-[e:transaction]- COST e.amount)* (b:Account)
- ON financial_transactions
-WHERE a.number = 10039 AND b.number = 2090
-
-SELECT *
-FROM GRAPH_TABLE(financial_transactions
- MATCH (p1 IS Person) (-[e IS owner|transaction]- COST CASE
- WHEN e.amount IS NULL THEN 1
- ELSE e.amount
- END)* (p2 IS Person)
- KEEP ANY CHEAPEST
- WHERE p1.name = 'Nikita' AND p2.name = 'Liam'
- COLUMNS(COUNT(EDGE_ID(e)) AS num_hops ,
- SUM(e.amount) AS total_amount ,
- ARRAY_AGG(e.amount) AS amounts_along_path))
-
-SELECT COUNT(e) AS num_hops
- , SUM(e.amount) AS total_amount
- , ARRAY_AGG(e.amount) AS amounts_along_path
-FROM MATCH ANY CHEAPEST (p1:Person) (-[e:owner|transaction]-
- COST CASE
- WHEN e.amount IS NULL THEN 1
- ELSE e.amount
- END)* (p2:Person)
- ON financial_transactions
-WHERE p1.name = 'Nikita' AND p2.name = 'Liam'
-
-SELECT *
-FROM GRAPH_TABLE(financial_transactions
- MATCH (a IS Account) (-[e IS transaction]-> COST e.amount)* (a)
- KEEP CHEAPEST 3 PATHS
- WHERE a.number = 10039
- COLUMNS(COUNT(EDGE_ID(e)) AS num_hops,
- SUM(e.amount) AS total_amount ,
- ARRAY_AGG(e.amount) AS amounts_along_path))
-ORDER BY total_amount
-
-SELECT COUNT(e) AS num_hops
- , SUM(e.amount) AS total_amount
- , ARRAY_AGG(e.amount) AS amounts_along_path
-FROM MATCH CHEAPEST 3 PATHS (a:Account) (-[e:transaction]-> COST e.amount)* (a)
- ON financial_transactions
-WHERE a.number = 10039
-ORDER BY total_amount
-
-SELECT *
-FROM GRAPH_TABLE(financial_transactions
- MATCH (a IS Account)
- (-[e]- (n_x) COST CASE WHEN n_x IS LABELED Person THEN 3 ELSE 1 END)*
- (c IS Company)
- KEEP CHEAPEST 4 PATHS
- WHERE a.number = 10039 AND c.name = 'Oracle'
- COLUMNS(COUNT(EDGE_ID(e)) AS num_hops ,
- ARRAY_AGG(CASE
- WHEN n_x IS LABELED Person THEN n_x.name
- WHEN n_x IS LABELED Company THEN n_x.name
- WHEN n_x IS LABELED Account THEN CAST(n_x.number AS STRING)
- END ) AS names_or_numbers ,
- SUM(CASE WHEN n_x IS LABELED Person THEN 8 ELSE 1 END) AS total_cost))
-ORDER BY total_cost
-
-SELECT COUNT(e) AS num_hops
- , ARRAY_AGG( CASE label(n_x)
- WHEN 'Person' THEN n_x.name
- WHEN 'Company' THEN n_x.name
- WHEN 'Account' THEN CAST(n_x.number AS STRING)
- END ) AS names_or_numbers
- , SUM( CASE label(n_x) WHEN 'Person' THEN 8 ELSE 1 END ) AS total_cost
-FROM MATCH CHEAPEST 4 PATHS
+```sql
+SELECT COUNT(e) AS num_hops
+ , ARRAY_AGG( CASE label(n_x)
+ WHEN 'Person' THEN n_x.name
+ WHEN 'Company' THEN n_x.name
+ WHEN 'Account' THEN CAST(n_x.number AS STRING)
+ END ) AS names_or_numbers
+ , SUM( CASE label(n_x) WHEN 'Person' THEN 8 ELSE 1 END ) AS total_cost
+FROM MATCH CHEAPEST 4 PATHS
(a:Account)
- (-[e]- (n_x) COST CASE label(n_x) WHEN 'Person' THEN 3 ELSE 1 END)*
- (c:Company) ON financial_transactions
-WHERE a.number = 10039 AND c.name = 'Oracle'
-ORDER BY total_cost
-
-SELECT *
-FROM GRAPH_TABLE(financial_transactions
- MATCH (a IS account) (-[e IS transaction]-> COST e.amount)* (a)
- KEEP CHEAPEST 4 WALK
- WHERE a.number = 10039
- COLUMNS(LISTAGG(e.amount, ', ') AS amounts_along_path, SUM(e.amount) AS total_cost))
-ORDER BY total_cost
-
-SELECT LISTAGG(e.amount, ', ') AS amounts_along_path, SUM(e.amount) AS total_cost
-FROM MATCH CHEAPEST 4 WALK (a:account) (-[e:transaction]-> COST e.amount)* (a)
- ON financial_transactions
-WHERE a.number = 10039
-ORDER BY total_cost
-
+SELECT name, total_transacted, top_transaction
+FROM LATERAL ( SELECT p1_id, name, SUM(amount) AS total_transacted
+ FROM GRAPH_TABLE(financial_transactions MATCH (p1 IS person) <- (a1 IS account) -[t1 IS transaction]- ()
+ COLUMNS(VERTEX_ID(p1) AS p1_id, p1.name, t1.amount))
+ GROUP BY p1_id, name
+ ORDER BY total_transacted DESC
+ FETCH FIRST 2 ROW ONLY ),
+ LATERAL ( SELECT amount AS top_transaction
+ FROM GRAPH_TABLE(financial_transactions MATCH (p2 IS Person) <- (a2 IS account) -[t2 IS transaction]- ()
+ COLUMNS(VERTEX_ID(p2) AS p2_id, t2.amount))
+ WHERE p2_id = p1_id
+ ORDER BY amount DESC
+ FETCH FIRST 2 ROW ONLY )
+ORDER BY total_transacted DESC, top_transaction DESC
+
+SELECT p.name, total_transacted, top_transaction
+FROM LATERAL ( SELECT p, SUM(t.amount) AS total_transacted
+ FROM MATCH (p:person) <- (a:account) -[t:transaction]- ()
+ ON financial_transactions
+ GROUP BY p
+ ORDER BY total_transacted DESC
+ FETCH FIRST 2 ROW ONLY ),
+ LATERAL ( SELECT t.amount AS top_transaction
+ FROM MATCH (p) <- (a:account) -[t:transaction]- ()
+ ON financial_transactions
+ ORDER BY t.amount DESC
+ FETCH FIRST 2 ROW ONLY )
+ORDER BY total_transacted DESC, top_transaction DESC
+