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

Support for Refresh Materialized View #2264

Closed
friedemannf opened this issue May 5, 2023 · 1 comment · Fixed by #2347
Closed

Support for Refresh Materialized View #2264

friedemannf opened this issue May 5, 2023 · 1 comment · Fixed by #2347

Comments

@friedemannf
Copy link

What do you want to change?

While playing around with Postgres Materialized Views I noticed that support for querying them was added in #1509 but I can't find a way to refresh them using sqlc.

I'd expect the following query to generate a method just like any exec annotation would:

-- name: RefreshFooView :exec
REFRESH MATERIALIZED VIEW foo_view;
RefreshFooView(ctx context.Context) error

Looking at the source code, it seems like ast.RefreshMatViewStmt is already being parsed but ignored as an unsupported statement. Is there any other way to refresh a Materialized View without falling back to the raw database connection or could support for this query be added to sqlc?

What database engines need to be changed?

PostgreSQL

What programming language backends need to be changed?

Go

@friedemannf friedemannf added enhancement New feature or request triage New issues that hasn't been reviewed labels May 5, 2023
@panthershark
Copy link

You can do this today by putting the tasks like refresh view inside of a function like this.

CREATE OR REPLACE FUNCTION public.refresh_views()
RETURNS boolean
LANGUAGE plpgsql
AS $$
  BEGIN
	REFRESH MATERIALIZED VIEW foo_view;
	RETURN true;
  END
$$;

Then change your sqlc to

-- name: RefreshFooView :exec
SELECT refresh_views();

If I was maintaining this project, I'd want to avoid adding features that have reasonable alternate implementations to ensure the project could stay focused. This seems reasonable to me.

@kyleconroy kyleconroy added 📚 postgresql 🔧 golang and removed triage New issues that hasn't been reviewed labels Jun 6, 2023
Jille added a commit to Jille/sqlc that referenced this issue Jun 21, 2023
The engine already understood it, just had to teach the compiler.

closes sqlc-dev#2264
kyleconroy pushed a commit that referenced this issue Jun 21, 2023
The engine already understood it, just had to teach the compiler.

closes #2264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants