|
1 | 1 | <!--
|
2 |
| -$PostgreSQL: pgsql/doc/src/sgml/ref/do.sgml,v 1.1 2009/09/22 23:43:37 tgl Exp $ |
| 2 | +$PostgreSQL: pgsql/doc/src/sgml/ref/do.sgml,v 1.2 2009/09/23 15:41:51 tgl Exp $ |
3 | 3 | PostgreSQL documentation
|
4 | 4 | -->
|
5 | 5 |
|
@@ -42,6 +42,11 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
|
42 | 42 | with no parameters, returning <type>void</>. It is parsed and
|
43 | 43 | executed a single time.
|
44 | 44 | </para>
|
| 45 | + |
| 46 | + <para> |
| 47 | + The optional <literal>LANGUAGE</> clause can be written either |
| 48 | + before or after the code block. |
| 49 | + </para> |
45 | 50 | </refsect1>
|
46 | 51 |
|
47 | 52 | <refsect1>
|
@@ -91,17 +96,20 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
|
91 | 96 | <refsect1 id="sql-do-examples">
|
92 | 97 | <title id="sql-do-examples-title">Examples</title>
|
93 | 98 | <para>
|
94 |
| - Execute a simple PL/pgsql loop without needing to create a function: |
| 99 | + Grant all privileges on all views in schema <literal>public</> to |
| 100 | + role <literal>webuser</>: |
95 | 101 | <programlisting>
|
96 |
| -DO $$ |
97 |
| -DECLARE r record; |
| 102 | +DO $$DECLARE r record; |
98 | 103 | BEGIN
|
99 |
| - FOR r IN SELECT rtrim(roomno) AS roomno, comment FROM Room ORDER BY roomno |
| 104 | + FOR r IN SELECT table_schema, table_name FROM information_schema.tables |
| 105 | + WHERE table_type = 'VIEW' AND table_schema = 'public' |
100 | 106 | LOOP
|
101 |
| - RAISE NOTICE '%, %', r.roomno, r.comment; |
| 107 | + EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser'; |
102 | 108 | END LOOP;
|
103 | 109 | END$$;
|
104 | 110 | </programlisting>
|
| 111 | + This example assumes that <varname>default_do_language</> has its |
| 112 | + default value, namely <literal>plpgsql</>. |
105 | 113 | </para>
|
106 | 114 | </refsect1>
|
107 | 115 | <refsect1>
|
|
0 commit comments