I am getting the below error while trying to use recursive CTE to fetch data that meets a certain condition.
Parse error on line 1: WITH RECURSIVE EquivalentParts AS ( ---------------^ Expecting 'AS', got 'LITERAL'
What I actually want is the query to output all parts that are transitively equivalent to PN0001 through the recursive process. Here is the content of table:
part_id | equivalent_part_id |
---|---|
PN0001 | PN0002 |
PN0002 | PN0003 |
PN0003 | PN0004 |
PN0004 | PN0005 |
PN0005 | PN0006 |
PN0006 | PN0007 |
PN0007 | PN0008 |
PN0008 | PN0009 |
PN0009 | PN0010 |
PN00013 | PN00011 |
PN00015 | PN00012 |
PN00016 | PN00014 |
PN0007 | PN00018 |
Here is the query I am using:
WITH RECURSIVE EquivalentParts AS (
SELECT eqvP.part_id, eqvP.equivalent_part_id
FROM {{ getPartsEquivalency.data }} AS eqvP
WHERE eqvP.part_id = 'PN0001'
UNION ALL
SELECT pe.part_id, pe.equivalent_part_id
FROM {{ getPartsEquivalency.data }} AS pe
INNER JOIN EquivalentParts AS ep
ON pe.part_id = ep.equivalent_part_id
)
SELECT part_id, equivalent_part_id
FROM EquivalentParts;
I think CTEs don’t work in Retool the same way they do in databases. Can anyone help me with this?
Thanks!