https://www.timescale.com/learn/how-to-use-common-table-expression-sql
WITH RECURSIVE
2024/8/24 8:42:00
SKKサーバーに文節機能つけたろwwwww
SQLで分かち書きしたろwwwww
WITH RECURSIVE hoge AS MATERIALIZED
濫用部になってる。
「SQLで分かち書きしようとする人、全員バカです」になってる。大変すぎる。
こいつを実行するとな、
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文をまわす方が簡単じゃな。