query

Recursive CTE SEARCH

SEARCH generates an ordering column for traversal presentation; it does not require the executor to visit rows in that order.

Formal Syntax & Structure

sql syntaxsql
SEARCH DEPTH FIRST BY n SET ord

Working Example

Example Snippetsql
CREATE TABLE a(id int primary key,k int); CREATE TABLE b(k int); INSERT INTO a VALUES (1,10),(2,20),(3,NULL); INSERT INTO b VALUES (10),(10),(NULL);WITH RECURSIVE t(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM t WHERE n<3) SEARCH DEPTH FIRST BY n SET ord SELECT n FROM t ORDER BY ord;
SQL Reference