0

我不知道如何使这个查询在使用 Knex 时起作用。该查询在我的 SQL 客户端中运行良好。

使用 postgis:latest image / latest Knex version

WITH RECURSIVE childs AS (
    SELECT id, ARRAY[id] as path, false as cycle FROM taxonomy WHERE taxonomy.id = 4
UNION
    SELECT T.id, path || T.id, T.id = ANY(path) FROM taxonomy T INNER JOIN childs C ON C.id = T.parent_id AND NOT cycle
)
SELECT id FROM childs

我试过了

client
    .withRecursive(
      'childs',
      knex.raw(
        `SELECT id, ARRAY[id] as path, false as cycle FROM taxonomy WHERE taxonomy.id = ?
       UNION
       SELECT T.id, path || T.id, T.id = ANY(path) FROM taxonomy T INNER JOIN childs C ON C.id = T.parent_id AND NOT cycle`,
        [4]
      )
    )
    .select('id')
    .from('childs')

但它给了我这个错误:SELECT * with no tables specified is not valid

有任何想法吗 ?

4

0 回答 0