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

Commite33eeb2

Browse files
committed
Improve example for DO, per Petr Jelinek.
1 parentc2bb037 commite33eeb2

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

‎doc/src/sgml/ref/do.sgml

Lines changed: 14 additions & 6 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp