WITH RECURSIVE pops (id, level, name, name_path) AS (
SELECT id, 0, name, ARRAY[name]
FROM categories
WHERE parent_category_id is null
UNION ALL
SELECT p.id, t0.level + 1, p.name, ARRAY_APPEND(t0.name_path, p.name)
FROM categories p
INNER JOIN pops t0 ON t0.id = p.parent_category_id
)
SELECT id,level, name_path[1] AS category, ARRAY_TO_STRING(name_path, ' > ')
FROM pops;
如何使用花岗岩orm在琥珀色水晶应用中执行上述查询