Skip to content

Commit

Permalink
fix: postgresql alter materialized view is not registered to statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulung Ragil committed Nov 28, 2024
1 parent 60f1b88 commit 02a80e5
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/3371
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- name: GetAuthorMv :one
SELECT * FROM authors_mv
WHERE id = $1 LIMIT 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);

CREATE MATERIALIZED VIEW authors_mv AS (
SELECT * FROM authors
);

CREATE MATERIALIZED VIEW authors_mv_new AS (
SELECT * FROM authors
);

ALTER MATERIALIZED VIEW authors_mv RENAME TO authors_mv_old;
ALTER MATERIALIZED VIEW authors_mv_new RENAME TO authors_mv;

DROP MATERIALIZED VIEW authors_mv_old;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "pgx/v4"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"contexts": ["managed-db"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- name: GetAuthorMv :one
SELECT * FROM authors_mv
WHERE id = $1 LIMIT 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);

CREATE MATERIALIZED VIEW authors_mv AS (
SELECT * FROM authors
);

CREATE MATERIALIZED VIEW authors_mv_new AS (
SELECT * FROM authors
);

ALTER MATERIALIZED VIEW authors_mv RENAME TO authors_mv_old;
ALTER MATERIALIZED VIEW authors_mv_new RENAME TO authors_mv;

DROP MATERIALIZED VIEW authors_mv_old;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "pgx/v5"
2 changes: 1 addition & 1 deletion internal/engine/postgresql/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func translate(node *nodes.Node) (ast.Node, error) {
MissingOk: n.MissingOk,
}, nil

case nodes.ObjectType_OBJECT_TABLE:
case nodes.ObjectType_OBJECT_TABLE, nodes.ObjectType_OBJECT_MATVIEW, nodes.ObjectType_OBJECT_VIEW:
rel := parseRelationFromRangeVar(n.Relation)
return &ast.RenameTableStmt{
Table: rel.TableName(),
Expand Down

0 comments on commit 02a80e5

Please sign in to comment.