Last active
August 29, 2023 17:05
-
-
Save Elektordi/a5e0c6634d228f03f873b7dbe313cf6a to your computer and use it in GitHub Desktop.
Refresh all materialized views in a schema (Postgres)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION remote.refresh() | |
RETURNS bool | |
LANGUAGE plpgsql | |
AS $$ | |
DECLARE | |
r record; | |
BEGIN | |
for r in SELECT matviewname FROM pg_catalog.pg_matviews where schemaname = 'remote' | |
loop | |
raise notice 'Refreshing %...', r.matviewname; | |
execute 'REFRESH MATERIALIZED VIEW CONCURRENTLY remote.' || quote_ident(r.matviewname) || ';'; | |
end loop; | |
return true; | |
END; | |
$$ | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment