Skip to content

Commit

Permalink
Support for parsing REFRESH MATERIALIZED VIEW (#2347)
Browse files Browse the repository at this point in the history
The engine already understood it, just had to teach the compiler.

closes #2264
  • Loading branch information
Jille authored Jun 21, 2023
1 parent f086636 commit e6548cd
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (c *Compiler) outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, er
}
case *ast.CallStmt:
targets = &ast.List{}
case *ast.TruncateStmt:
case *ast.TruncateStmt, *ast.RefreshMatViewStmt:
targets = &ast.List{}
case *ast.UpdateStmt:
targets = n.ReturningList
Expand Down Expand Up @@ -480,6 +480,11 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
_, ok := node.(*ast.RangeVar)
return ok
})
case *ast.RefreshMatViewStmt:
list = astutils.Search(n.Relation, func(node ast.Node) bool {
_, ok := node.(*ast.RangeVar)
return ok
})
case *ast.UpdateStmt:
list = &ast.List{
Items: append(n.FromClause.Items, n.Relations.Items...),
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (c *Compiler) parseQuery(stmt ast.Node, src string, o opts.Parser) (*Query,
}
case *ast.TruncateStmt:
case *ast.UpdateStmt:
case *ast.RefreshMatViewStmt:
default:
return nil, ErrUnsupportedStatementType
}
Expand Down

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,4 @@
CREATE MATERIALIZED VIEW myview AS (SELECT 1);

-- name: Refresh :exec
REFRESH MATERIALIZED VIEW myview;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql",
}
]
}

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,4 @@
CREATE MATERIALIZED VIEW myview AS (SELECT 1);

-- name: Refresh :exec
REFRESH MATERIALIZED VIEW myview;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "1",
"packages": [
{
"path": "go",
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "query.sql",
"queries": "query.sql",
}
]
}

0 comments on commit e6548cd

Please sign in to comment.