Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error in CTE recursive query #415

Open
Alexnortung opened this issue Aug 12, 2024 · 0 comments
Open

Syntax error in CTE recursive query #415

Alexnortung opened this issue Aug 12, 2024 · 0 comments

Comments

@Alexnortung
Copy link
Contributor

Alexnortung commented Aug 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant