Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e33eeb2

Browse files
committed
Improve example for DO, per Petr Jelinek.
1 parent c2bb037 commit e33eeb2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

doc/src/sgml/ref/do.sgml

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
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 $
33
PostgreSQL documentation
44
-->
55

@@ -42,6 +42,11 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
4242
with no parameters, returning <type>void</>. It is parsed and
4343
executed a single time.
4444
</para>
45+
46+
<para>
47+
The optional <literal>LANGUAGE</> clause can be written either
48+
before or after the code block.
49+
</para>
4550
</refsect1>
4651

4752
<refsect1>
@@ -91,17 +96,20 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla
9196
<refsect1 id="sql-do-examples">
9297
<title id="sql-do-examples-title">Examples</title>
9398
<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</>:
95101
<programlisting>
96-
DO $$
97-
DECLARE r record;
102+
DO $$DECLARE r record;
98103
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'
100106
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';
102108
END LOOP;
103109
END$$;
104110
</programlisting>
111+
This example assumes that <varname>default_do_language</> has its
112+
default value, namely <literal>plpgsql</>.
105113
</para>
106114
</refsect1>
107115
<refsect1>

0 commit comments

Comments
 (0)