Skip to content

Commit 6bcb4c2

Browse files
committed
Rename variable in recursive CTEs in SQL queries: s/depth/level/g
1 parent 02ca463 commit 6bcb4c2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
WITH RECURSIVE search_graph(link, depth, path) AS (
1+
WITH RECURSIVE search_graph(link, level, path) AS (
22
SELECT :person1Id::bigint, 0, ARRAY[:person1Id::bigint]::bigint[]
33
UNION ALL
4-
(WITH sg(link,depth) as (select * from search_graph) -- Note: sg is only the diff produced in the previous iteration
5-
SELECT distinct k_person2id, x.depth+1, array_append(path, k_person2id)
4+
(WITH sg(link,level) as (select * from search_graph) -- Note: sg is only the diff produced in the previous iteration
5+
SELECT distinct k_person2id, x.level+1, array_append(path, k_person2id)
66
FROM knows, sg x
77
WHERE 1=1
88
and x.link = k_person1id
@@ -13,6 +13,6 @@ WITH RECURSIVE search_graph(link, depth, path) AS (
1313
and not exists(select * from sg y where y.link = k_person2id)
1414
)
1515
)
16-
select max(depth) from (
17-
select depth from search_graph where link = :person2Id::bigint
16+
select max(level) from (
17+
select level from search_graph where link = :person2Id::bigint
1818
union select -1) tmp;

postgres/queries/interactive-complex-14.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ WITH start_node(v) AS (
33
)
44
select * from (
55
WITH RECURSIVE
6-
search_graph(link, depth, path) AS (
6+
search_graph(link, level, path) AS (
77
(SELECT v::bigint, 0, ARRAY[]::bigint[][] from start_node)
88
UNION ALL
9-
(WITH sg(link,depth) as (select * from search_graph)
10-
SELECT distinct k_person2id, x.depth + 1,path || ARRAY[[x.link, k_person2id]]
9+
(WITH sg(link,level) as (select * from search_graph)
10+
SELECT distinct k_person2id, x.level + 1,path || ARRAY[[x.link, k_person2id]]
1111
FROM knows, sg x
1212
WHERE x.link = k_person1id and not exists(select * from sg y where y.link = :person2Id::bigint) and not exists( select * from sg y where y.link=k_person2id)
1313
)

0 commit comments

Comments
 (0)