Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1fcb73f

Browse files
author
Amit Kapila
committed
Doc: Update PL/pgSQL sample function in plpgsql.sgml.
The example used to explain 'Looping Through Query Results' usespseudo-materialized views. Replace it with a more up-to-date examplewhich does the same thing with actual materialized views, which havebeen available since PostgreSQL 9.3.In the passing, change '%' as format specifier instead of '%s' as is usedin other examples in plpgsql.sgml.Reported-by: Ian BarwickAuthor: Ian BarwickReviewed-by: Amit KapilaBackpatch-through: 9.4Discussion:https://postgr.es/m/9a70d393-7904-4918-c97c-649f6d114b6a@2ndquadrant.com
1 parent8da17f3 commit1fcb73f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

‎doc/src/sgml/plpgsql.sgml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,19 +2445,29 @@ END LOOP <optional> <replaceable>label</replaceable> </optional>;
24452445
resulting from the <replaceable>query</replaceable> and the loop body is
24462446
executed for each row. Here is an example:
24472447
<programlisting>
2448-
CREATE FUNCTIONcs_refresh_mviews() RETURNS integer AS $$
2448+
CREATE FUNCTIONrefresh_mviews() RETURNS integer AS $$
24492449
DECLARE
24502450
mviews RECORD;
24512451
BEGIN
2452-
RAISE NOTICE 'Refreshing materialized views...';
2453-
2454-
FOR mviews IN SELECT * FROM cs_materialized_views ORDER BY sort_key LOOP
2452+
RAISE NOTICE 'Refreshing all materialized views...';
2453+
2454+
FOR mviews IN
2455+
SELECT n.nspname AS mv_schema,
2456+
c.relname AS mv_name,
2457+
pg_catalog.pg_get_userbyid(c.relowner) AS owner
2458+
FROM pg_catalog.pg_class c
2459+
LEFT JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace)
2460+
WHERE c.relkind = 'm'
2461+
ORDER BY 1
2462+
LOOP
24552463

2456-
-- Now "mviews" has one recordfrom cs_materialized_views
2464+
-- Now "mviews" has one recordwith information about the materialized view
24572465

2458-
RAISE NOTICE 'Refreshing materialized view %s ...', quote_ident(mviews.mv_name);
2459-
EXECUTE format('TRUNCATE TABLE %I', mviews.mv_name);
2460-
EXECUTE format('INSERT INTO %I %s', mviews.mv_name, mviews.mv_query);
2466+
RAISE NOTICE 'Refreshing materialized view %.% (owner: %)...',
2467+
quote_ident(mviews.mv_schema),
2468+
quote_ident(mviews.mv_name),
2469+
quote_ident(mviews.owner);
2470+
EXECUTE format('REFRESH MATERIALIZED VIEW %I.%I', mviews.mv_schema, mviews.mv_name);
24612471
END LOOP;
24622472

24632473
RAISE NOTICE 'Done refreshing materialized views.';

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp