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

Renaming a materialized view causes sqlc generate to fail #3371

Open
JakeCapra opened this issue May 9, 2024 · 0 comments
Open

Renaming a materialized view causes sqlc generate to fail #3371

JakeCapra opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@JakeCapra
Copy link

Version

1.22.0

What happened?

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 as select x.* from (values(1), (1), (1)) as x;

create materialized view view_2 as select x.* from (values(2), (2), (2)) as x;

drop materialized view view_1;

alter materialized view view_2 rename to view_1;

SQL queries

-- name: SelectView :many
select * from view_1;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/f5ae38a7ec5718c27c64bbc03eccf3f118b68bfdf5d163a3f9caa4296cdfe5bb

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@JakeCapra JakeCapra added bug Something isn't working triage New issues that hasn't been reviewed labels May 9, 2024
@JakeCapra JakeCapra changed the title Renaming a materialized view causes sqlc generate to fail SQLC does not detect alter materialized view ... rename to .. May 10, 2024
@JakeCapra JakeCapra changed the title SQLC does not detect alter materialized view ... rename to .. Renaming a materialized view causes sqlc generate to fail May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

No branches or pull requests

1 participant