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

feat(postgresql): Add ALTER VIEW ... SET SCHEMA #2855

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1519

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,2 @@
-- name: SomeQuery :many
select id from "computed_tables"."something";
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
create table events (
id int,
event_type text not null,
created_at timestamptz
);

CREATE MATERIALIZED VIEW something AS
select * from events
where event_type = 'sale'
order by created_at desc;

create schema computed_tables;
alter materialized view something set schema computed_tables;
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 @@ -236,7 +236,7 @@ func translate(node *nodes.Node) (ast.Node, error) {
n := inner.AlterObjectSchemaStmt
switch n.ObjectType {

case nodes.ObjectType_OBJECT_TABLE:
case nodes.ObjectType_OBJECT_TABLE, nodes.ObjectType_OBJECT_VIEW, nodes.ObjectType_OBJECT_MATVIEW:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Internally, the sqlc catalog stores views and materialized views as tables.

rel := parseRelationFromRangeVar(n.Relation)
return &ast.AlterTableSetSchemaStmt{
Table: rel.TableName(),
Expand Down
Loading