pg-mem
pg-mem copied to clipboard
Syntax error in CTE recursive query
Describe the bug
I am trying to run a query with a CTE recursive query. However it says that it wasn't expecting AS
, but that is a valid postgres query and I could run it fine outside of pg-mem
QueryFailedError: 💔 Your query failed to parse.
This is most likely due to a SQL syntax error. However, you might also have hit a bug, or an unimplemented feature of pg-mem.
If this is the case, please file an issue at https://github.com/oguimbal/pg-mem along with a query that reproduces this syntax error.
👉 Failed query:
WITH RECURSIVE company_real_ownership AS (
SELECT
cvr
, 1.0 AS real_ownership
FROM company
WHERE cvr = '1234'
UNION
SELECT comp.cvr, comp.name, CAST(cc.share * cr.real_ownership AS NUMERIC) AS real_ownership FROM company comp
INNER JOIN company_company_ownership cc ON comp.cvr = cc.owner_id
INNER JOIN company_real_ownership cr ON cc.company_id = cr.cvr
WHERE cc.valid_to IS NULL
)
SELECT p.id AS person_id, SUM(cro.real_ownership * pco.share) AS real_share FROM person p
INNER JOIN person_company_ownership pco ON pco.person_id = p.id
INNER JOIN company_real_ownership cro ON cro.cvr = pco.company_id
WHERE pco.valid_to IS NULL
AND pco.relation_type = 'legal'
GROUP BY p.id
;
💀 Syntax error at line 2 col 51:
1 AND pco.relation_type = 'legal'
2 GROUP BY p.id
^
3 ;
Unexpected kw_as token: "as". Instead, I was expecting to see one of the following:
- A "lparen" token
pg-mem version
2.9.1
and 3.0.2