Skip to content

Recursive query.  #1161

Closed
Closed
@stigmat4j

Description

@stigmat4j

I use sequelize-postgres npm for my nodejs project. The structure of my db

id: Sequelize.INTEGER,
sponsor: Sequelize.INTEGER,
depth: Sequelize.INTEGER,
path: Sequelize.TEXT,
parents: Sequelize.INTEGER,
cycle: Sequelize.INTEGER
Query for db

WITH RECURSIVE
nodes_cte(id, sponsor, depth, path, parents, cycle) AS (
SELECT tn.id, tn.sponsor,
1 AS depth,
'tn.id' AS path,
ARRAY[tn.id],
false
FROM referrals tn
WHERE tn.sponsor = 0
UNION ALL
SELECT c.id, c.sponsor,
p.depth + 1 AS depth,
(p.path || '->' || c.id),
p.parents || p.id,
c.id = ANY(p.parents)
FROM nodes_cte AS p,
referrals AS c
WHERE c.sponsor = p.id
AND NOT p.cycle
)
SELECT * FROM nodes_cte AS n;

If i make the query through Sequelize - i receive empty array. But when i do it through console i receive normal result.

Help me to solve my problem please.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions