Improve example for DO, per Petr Jelinek.
authorTom Lane
Wed, 23 Sep 2009 15:41:51 +0000 (15:41 +0000)
committerTom Lane
Wed, 23 Sep 2009 15:41:51 +0000 (15:41 +0000)
doc/src/sgml/ref/do.sgml

index 2fb538066303d82e5ccc103afdfd40814e3db453..0a851447263ab8794a7baace788084cbc37ed2d2 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -42,6 +42,11 @@ DO code [ LANGUAGE 
    with no parameters, returning 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.