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

Make it possible to use create_or_replace_view with materialized view. #2144

Merged
merged 1 commit into from Mar 27, 2024

Conversation

nashby
Copy link
Contributor

@nashby nashby commented Mar 27, 2024

It's not possible to use CREATE OR REPLACE with materialized view in Postgres so we should fallback to drop_view/create_view calls when we use create_or_replace_view method with :materialized option.

Currently when create_or_replace_view is called you get

Sequel::DatabaseError: PG::SyntaxError: ERROR:  syntax error at or near "MATERIALIZED"
LINE 1: CREATE OR REPLACE MATERIALIZED VIEW "items_view" AS SELECT *...

It's not possible to use CREATE OR REPLACE with materialized view in Postgres so we should fallback
to `drop_view`/`create_view` calls when we use `create_or_replace_view` method with `:materialized`
option.
@@ -252,10 +252,10 @@ def create_table_generator(&block)
# For databases where replacing a view is not natively supported, support
# is emulated by dropping a view with the same name before creating the view.
def create_or_replace_view(name, source, options = OPTS)
if supports_create_or_replace_view?
if supports_create_or_replace_view? && !options[:materialized]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure if it's too specific for postgres and we should have separate create_or_replace_view specifically for postgres. let me know if you want to change that

@jeremyevans
Copy link
Owner

Thanks for the patch! I think your implementation looks fine. If we do eventually have another database that supports replacing materialized views, we can adjust at that point.

@jeremyevans jeremyevans merged commit 1ffa233 into jeremyevans:master Mar 27, 2024
16 checks passed
@nashby nashby deleted the replace-materialized-view branch March 27, 2024 16:41
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.

None yet

2 participants