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

sql: add unimplemented error for recursive query without union all #46378

Closed
awoods187 opened this issue Mar 20, 2020 · 1 comment · Fixed by #46643
Closed

sql: add unimplemented error for recursive query without union all #46378

awoods187 opened this issue Mar 20, 2020 · 1 comment · Fixed by #46643
Assignees
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@awoods187
Copy link
Contributor

Consider this table:

CREATE TABLE edges (
   src integer,
   dest integer
);

INSERT INTO edges (
    src,
    dest
)
VALUES
    (1, 2),
    (2, 3),
    (2, 4),
    (3, 4),
    (4, 1),
    (3, 5);

And this query:

WITH RECURSIVE paths (src, dest, path) AS (
        SELECT e.src, e.dest, ARRAY[e.src, e.dest]
        FROM edges e
    UNION
        SELECT p.src, e.dest, p.path || ARRAY[e.dest]
        FROM paths p
        JOIN edges e
        ON p.dest = e.src AND e.dest != ALL(p.path)
)
SELECT * FROM paths;

Returns:

ERROR: recursive query "paths" does not have the form non-recursive-term UNION ALL recursive-term
SQLSTATE: 42601

We should update this to include the unimplemeted error and github issue.

@awoods187 awoods187 added A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) labels Mar 20, 2020
@RaduBerinde
Copy link
Member

Is there an issue for recursive CTEs with UNION? I seem to recall you filed one but I can't find it.

RaduBerinde added a commit to RaduBerinde/cockroach that referenced this issue Mar 26, 2020
…CTEs

Postgres supports a variant of recursive CTEs that uses UNION instead
of UNION ALL. We don't support it as of yet; this commit improves the
error returned in this case.

Fixes cockroachdb#46378.

Release note: None

Release justification: low risk change to new functionality.
craig bot pushed a commit that referenced this issue Mar 27, 2020
46643: opt: better error message for unsupported UNION variant of recursive CTEs r=RaduBerinde a=RaduBerinde

Postgres supports a variant of recursive CTEs that uses UNION instead
of UNION ALL. We don't support it as of yet; this commit improves the
error returned in this case.

Fixes #46378.

Release note: None

Release justification: low risk change to new functionality.

Co-authored-by: Radu Berinde <[email protected]>
@craig craig bot closed this as completed in 407cb4c Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants