Skip to content

Support for Refresh Materialized View #2264

Description

@friedemannf

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

Activity

  1. panthershark commented on May 19, 2023

    @panthershark

    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.

  2. added a commit that references this issue on Jun 21, 2023
    f62cb26
  3. added a commit that references this issue on Jun 21, 2023
    e6548cd
  4. added a commit that references this issue on Oct 13, 2025
    8950b51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions