Cockroach: sql: WITH RECURSIVE (recursive common table expressions)

Created on 28 Dec 2017  路  4Comments  路  Source: cockroachdb/cockroach

Split from #7029 which was closed when we merged support for single-use common table expressions in #20359.

Support WITH RECURSIVE, which allows a query to refer to its own output.

A simple example from Postgres's documentation sums the numbers from 1 to 100:

WITH RECURSIVE t(n) AS (
    VALUES (1)
  UNION ALL
    SELECT n+1 FROM t WHERE n < 100
)
SELECT sum(n) FROM t;

The t clause uses itself as a data source, which requires the RECURSIVE modifier to WITH. This feature likely requires temporary tables to perform well.

A-sql-optimizer A-sql-pgcompat C-enhancement X-anchored-telemetry

Most helpful comment

thumbs up for this. recursive queries from the client side could produce lots of network chatter on a big table. consider a hierarchical category system for an online store for a business case. defendants need to be queried for each user search and for category operations.

All 4 comments

Recursive CTEs are vital to storing graph or tree structures in a database and are even present in SQLite ;). Here's my specific use case: Calculating the Path of a Row in an Adjacency List When Recursive CTE Are Not Supported

any updates?

please consider add full support for tree structure, such as 'path, level, isLeaf, sort siblings'

Just wanted to add my request to have recursive CTEs supported and if accepted a timeline for when to expect it?

thumbs up for this. recursive queries from the client side could produce lots of network chatter on a big table. consider a hierarchical category system for an online store for a business case. defendants need to be queried for each user search and for category operations.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nvanbenschoten picture nvanbenschoten  路  3Comments

couchand picture couchand  路  3Comments

petermattis picture petermattis  路  4Comments

nvanbenschoten picture nvanbenschoten  路  3Comments

magaldima picture magaldima  路  3Comments