Skip to content

Fix: Enable schema binding when creating views for queries with recursive CTEs in redshift#4006

Merged
izeigerman merged 2 commits intomainfrom
fix-redhshift-schema-binding-for-recursive-ctes
Mar 17, 2025
Merged

Fix: Enable schema binding when creating views for queries with recursive CTEs in redshift#4006
izeigerman merged 2 commits intomainfrom
fix-redhshift-schema-binding-for-recursive-ctes

Conversation

@izeigerman
Copy link
Contributor

@izeigerman izeigerman commented Mar 17, 2025

We should always include NO SCHEMA BINDING when creating views in Redshift. Otherwise view creation fails when used with something like external tables.

At the same, views with NO SCHEMA BINDING can't be created for models that rely on recursive CTEs in their queries. This update makes it so that NO SCHEMA BINDING is omitted only when recursive CTES are used.

@izeigerman izeigerman force-pushed the fix-redhshift-schema-binding-for-recursive-ctes branch from 8b1d60a to ee548a5 Compare March 17, 2025 20:14
Comment on lines +223 to 225
has_recursive_cte = any(
w.args.get("recursive", False) for w in query_or_df.find_all(exp.With)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit] I think you can do With.recursive and that gets you a bool directly.

@izeigerman izeigerman merged commit f1d1504 into main Mar 17, 2025
22 checks passed
@izeigerman izeigerman deleted the fix-redhshift-schema-binding-for-recursive-ctes branch March 17, 2025 20:30
afzaljasani pushed a commit that referenced this pull request Apr 8, 2025
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.

4 participants