Skip to content

feat(duckdb): Add transpilation support for Snowflake STARTS WITH#7709

Open
fivetran-kwoodbeck wants to merge 3 commits into
mainfrom
transpile/snowflake-startswith
Open

feat(duckdb): Add transpilation support for Snowflake STARTS WITH#7709
fivetran-kwoodbeck wants to merge 3 commits into
mainfrom
transpile/snowflake-startswith

Conversation

@fivetran-kwoodbeck
Copy link
Copy Markdown
Collaborator

Adds Snowflake to DuckDB transpilation for START WITH ... CONNECT BY PRIOR hierarchical queries.

DuckDB rejects CONNECT BY verbatim. This adds connect_by_to_recursive_cte registered as a preprocessor on exp.Select, which rewrites the query into a WITH RECURSIVE CTE at generation time:

  • Anchors START WITH rows from the source table
  • Recursive arm: source table aliased _child_row joined to the CTE aliased _parent_row on the PRIOR predicate
  • Outer SELECT re-projects from _rootcte, applying WHERE post-hierarchy and forwarding ORDER BY, LIMIT, OFFSET

Falls through unchanged for NOCYCLE, multiple PRIORs, or non-equality predicates. CTE name collision is avoided via find_new_name. WHERE columns absent from SELECT are carried through the CTE so the outer filter can see them. LEVEL is injected as a depth counter unless already projected.

Tests in sqlglot-integration-tests cover: SELECT *, explicit column list with ORDER BY, PRIOR on left side, WHERE carry-through, existing CTE preservation, and name collision.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 4, 2026

SQLGlot Integration Test Results

✅ All tests passed

Comparing:

  • this branch (sqlglot:transpile/snowflake-startswith @ sqlglot 601a4bd)
  • baseline (main @ sqlglot 6ae53c2)

Overall

main: 113231 total, 112182 passed (pass rate: 99.1%)

sqlglot:transpile/snowflake-startswith: 106860 total, 106860 passed (pass rate: 100.0%)

Transitions:
No change

Dialect pair changes: 0 previous results not found, 2 current results not found

✅ All tests passed

@fivetran-kwoodbeck fivetran-kwoodbeck force-pushed the transpile/snowflake-startswith branch from 90cc2e1 to 9c55e84 Compare June 5, 2026 20:19
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

Successfully merging this pull request may close these issues.

1 participant