PostgreSQL 14.10 Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth- first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: WITH RECURSIVE search_tree(id, link, data, path)0 码力 | 3032 页 | 13.27 MB | 1 年前3
PostgreSQL 14.10 Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth-first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: 135 Queries WITH RECURSIVE search_tree(id, link0 码力 | 2871 页 | 13.38 MB | 1 年前3
PostgreSQL 13.13 DocumentationWITH RECURSIVE search_graph(id, link, data, depth) AS ( SELECT g.id, g.link, g.data, 1 FROM graph g UNION ALL SELECT g.id, g.link, g.data, sg.depth + 1 FROM graph g, search_graph sg search_graph; This query will loop if the link relationships contain cycles. Because we require a “depth” output, just changing UNION ALL to UNION would not eliminate the looping. Instead we need to recognize search_graph(id, link, data, depth, path, cycle) AS ( SELECT g.id, g.link, g.data, 1, ARRAY[g.id], false FROM graph g UNION ALL SELECT g.id, g.link, g.data, sg.depth + 1, path ||0 码力 | 2782 页 | 13.00 MB | 1 年前3
PostgreSQL 13.14 DocumentationWITH RECURSIVE search_graph(id, link, data, depth) AS ( SELECT g.id, g.link, g.data, 1 FROM graph g UNION ALL SELECT g.id, g.link, g.data, sg.depth + 1 FROM graph g, search_graph sg search_graph; This query will loop if the link relationships contain cycles. Because we require a “depth” output, just changing UNION ALL to UNION would not eliminate the looping. Instead we need to recognize search_graph(id, link, data, depth, path, cycle) AS ( SELECT g.id, g.link, g.data, 1, ARRAY[g.id], false FROM graph g UNION ALL SELECT g.id, g.link, g.data, sg.depth + 1, path ||0 码力 | 2940 页 | 12.89 MB | 1 年前3
PostgreSQL 15.5 Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth-first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: 137 Queries WITH RECURSIVE search_tree(id, link0 码力 | 2910 页 | 13.60 MB | 1 年前3
PostgreSQL 15.5 Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth- first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: WITH RECURSIVE search_tree(id, link, data, path)0 码力 | 3073 页 | 13.49 MB | 1 年前3
PostgreSQL 16.1 Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth- first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: WITH RECURSIVE search_tree(id, link, data, path)0 码力 | 3133 页 | 14.10 MB | 1 年前3
PostgreSQL 16.1 Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth-first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: 138 Queries WITH RECURSIVE search_tree(id, link0 码力 | 2974 页 | 14.22 MB | 1 年前3
PostgreSQL 17beta1 A4 Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth-first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: 140 Queries WITH RECURSIVE search_tree(id, link0 码力 | 3017 页 | 14.45 MB | 1 年前3
PostgreSQL 17beta1 US Documentationcomputing a tree traversal using a recursive query, you might want to order the results in either depth- first or breadth-first order. This can be done by computing an ordering column alongside the other nt. This approach merely provides a convenient way to order the results afterwards. To create a depth-first order, we compute for each result row an array of rows that we have visited so far. For example data FROM tree t, search_tree st WHERE t.id = st.link ) SELECT * FROM search_tree; To add depth-first ordering information, you can write this: WITH RECURSIVE search_tree(id, link, data, path)0 码力 | 3188 页 | 14.32 MB | 1 年前3
共 40 条
- 1
- 2
- 3
- 4













