You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Renaming a materialized view causes sqlc generate to fail #3371
I have to update the query that backs a materialized view.
To do this, I create a new temporary materialized view, view_2, drop the old view, view_1, and rename the temporary view to the old view's name.
I am renaming the temporary view using alter materialized view view_2 rename to view_1.
When I run sqlc generate, SQLC states that the view_1 does not exist, when in fact it does, it's just been renamed.
For context, I need to create a temporary materialized view, as dropping and recreating a materialized view will block all reads to the view. This is a two-step process, done in separate migrations. Postgres does not support updating a materialized view's query.
Relevant log output
# package db
query.sql:1:1: relation "view_1" does not exist
Database schema
create materialized view view_1 asselect x.*from (values(1), (1), (1)) as x;
create materialized view view_2 asselect x.*from (values(2), (2), (2)) as x;
drop materialized view view_1;
alter materialized view view_2 rename to view_1;
changed the title [-]Renaming a materialized view causes `sqlc generate` to fail[/-][+]SQLC does not detect `alter materialized view ... rename to ..`[/+]on May 10, 2024
changed the title [-]SQLC does not detect `alter materialized view ... rename to ..`[/-][+]Renaming a materialized view causes `sqlc generate` to fail[/+]on May 10, 2024
Note that this appears to impact all views (it's not specific to materialized views) - playground. I've hit this where one migration script renames a view, and then the subsequent one attempts to drop it (with the new name).
Activity
[-]Renaming a materialized view causes `sqlc generate` to fail[/-][+]SQLC does not detect `alter materialized view ... rename to ..`[/+][-]SQLC does not detect `alter materialized view ... rename to ..`[/-][+]Renaming a materialized view causes `sqlc generate` to fail[/+]MattBrittan commentedon May 30, 2024
Note that this appears to impact all views (it's not specific to materialized views) - playground. I've hit this where one migration script renames a view, and then the subsequent one attempts to drop it (with the new name).
Tested with v1.26.0
swallowstalker commentedon Nov 28, 2024
i can confirm that this bug is still active on v1.27.0
for create table - rename table - drop table it works just fine
https://play.sqlc.dev/p/84a2ae8f290ed9c8e79b73be43f6bae3e3658da1c38393c36ea6fc168f0923f2
but for create mv - rename mv - drop mv it says that the dropped mv is not found
https://play.sqlc.dev/p/f550f1c34ee6b5c97c40b6a0c9ffdfc59ea0091fb5cdae9e736cef9d309e2251
i'll try to look into the codebase and see what i can do