From ac55c9b31c99207d25a4d249d337a4e12bc06acd Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Wed, 23 Sep 2009 15:41:51 +0000
Subject: Improve example for DO, per Petr Jelinek.
---
doc/src/sgml/ref/do.sgml | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/doc/src/sgml/ref/do.sgml b/doc/src/sgml/ref/do.sgml
index f1e25e95c0..897d4a3f18 100644
--- a/doc/src/sgml/ref/do.sgml
+++ b/doc/src/sgml/ref/do.sgml
@@ -42,6 +42,11 @@ DO code [ LANGUAGE void>. It is parsed and
executed a single time.
+
+
+ The optional LANGUAGE> clause can be written either
+ before or after the code block.
+
@@ -91,17 +96,20 @@ DO code [ LANGUAGE
Examples
- Execute a simple PL/pgsql loop without needing to create a function:
+ Grant all privileges on all views in schema public> to
+ role webuser>:
-DO $$
-DECLARE r record;
+DO $$DECLARE r record;
BEGIN
- FOR r IN SELECT rtrim(roomno) AS roomno, comment FROM Room ORDER BY roomno
+ FOR r IN SELECT table_schema, table_name FROM information_schema.tables
+ WHERE table_type = 'VIEW' AND table_schema = 'public'
LOOP
- RAISE NOTICE '%, %', r.roomno, r.comment;
+ EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser';
END LOOP;
END$$;
+ This example assumes that default_do_language> has its
+ default value, namely plpgsql>.
--
cgit v1.2.3