-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Allow Non-Linear CTE #7259
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
Comments
Mike Bayer has proposed a fix for this issue in the master branch: Add Non linear CTE support https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3220 |
Eric Masseran has proposed a fix for this issue in the master branch: Add Non linear CTE support https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3256 |
Eric Masseran has proposed a fix for this issue in the main branch: Add Non linear CTE support https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3220 |
Eric Masseran has proposed a fix for this issue in the rel_1_4 branch: Add Non linear CTE support https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3312 |
"Compound select" methods like :meth:`_sql.Select.union`, :meth:`_sql.Select.intersect_all` etc. now accept ``*other`` as an argument rather than ``other`` to allow for multiple additional SELECTs to be compounded with the parent statement at once. In particular, the change as applied to :meth:`_sql.CTE.union` and :meth:`_sql.CTE.union_all` now allow for a so-called "non-linear CTE" to be created with the :class:`_sql.CTE` construct, whereas previously there was no way to have more than two CTE sub-elements in a UNION together while still correctly calling upon the CTE in recursive fashion. Pull request courtesy Eric Masseran. Allow: ```sql WITH RECURSIVE nodes(x) AS ( SELECT 59 UNION SELECT aa FROM edge JOIN nodes ON bb=x UNION SELECT bb FROM edge JOIN nodes ON aa=x ) SELECT x FROM nodes; ``` Based on @zzzeek suggestion: #7133 (comment) Fixes: #7259 Closes: #7260 Pull-request: #7260 Pull-request-sha: 2565a5f Change-Id: I685c8379762b5fb6ab4107ff8f4d8a4de70c0ca6 (cherry picked from commit 958f902)
Describe the use case
Non Linear CTE:
Useful for example to do graph traversal with directional edges. One UNION to one side and the other UNION to the other side.
Databases / Backends / Drivers targeted
SQLite & MySQL support its and maybe more. (Also: https://modern-sql.com/caniuse/with_recursive_(non-linear))
Example Use
From https://www.sqlite.org/lang_with.html at
3.3. Queries Against A Graph
.Additional context
No response
The text was updated successfully, but these errors were encountered: