Simple recursive common table expression (CTE)
-- ****************************************************************************
-- This is a very rudimentary recursive common table expression (CTE). By
-- modifying pieces of it, one can get a sense as to how a recursive CTE works.
-- ****************************************************************************
WITH RECURSIVE "t" AS
(
-- The top part of the UNION query sets the structure of the
-- query.
SELECT
1 AS "counter"
, CHR( 65 ) AS "extra"
, CHR( 65 ) AS "example"
-- The second half of the UNION query must include UNION ALL.
-- It must include the CTE in the FROM clause. And it MUST have
-- some kind of WHERE clause that will terminate the recursion.
UNION ALL
SELECT
counter + 1 AS "counter"
, CHR( 65 + counter ) AS "extra"
, example || CHR( 65 + counter ) AS "example"
FROM t
WHERE counter < 4
)
SELECT
counter
, extra
, example
FROM t
;