こいつを実行するとな、
WITH RECURSIVE
given AS NOT MATERIALIZED (
SELECT ? as text
),
token AS MATERIALIZED (
SELECT
LENGTH(given.text) AS tail,
0 as head,
RIGHT(LEFT(given.text, tail-head), tail) AS chunk,
FROM
given
UNION
SELECT
token.tail - 1 AS tail,
0 as head,
RIGHT(LEFT(token.chunk, tail-head), tail) AS chunk,
FROM
token
WHERE
tail > 0
)
SELECT * FROM token;
こうなるんじゃ
[
{
tail: 4n,
head: 0,
chunk: "test",
}, {
tail: 3n,
head: 0,
chunk: "test",
}, {
tail: 2n,
head: 0,
chunk: "tes",
}, {
tail: 1n,
head: 0,
chunk: "te",
}, {
tail: 0n,
head: 0,
chunk: "t",
}
]
素直にプログラミング言語でfor文をまわす方が簡単じゃな。