diff options
author | Tom Lane | 2009-09-23 15:41:51 +0000 |
---|---|---|
committer | Tom Lane | 2009-09-23 15:41:51 +0000 |
commit | ac55c9b31c99207d25a4d249d337a4e12bc06acd (patch) | |
tree | 2fa193479b2d0c31a13c240bfef955aa1a3a0bc2 | |
parent | 194845878796dcf6253484d360fc6f211aad76a1 (diff) |
Improve example for DO, per Petr Jelinek.
-rw-r--r-- | doc/src/sgml/ref/do.sgml | 18 |
1 files 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 <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla with no parameters, returning <type>void</>. It is parsed and executed a single time. </para> + + <para> + The optional <literal>LANGUAGE</> clause can be written either + before or after the code block. + </para> </refsect1> <refsect1> @@ -91,17 +96,20 @@ DO <replaceable class="PARAMETER">code</replaceable> [ LANGUAGE <replaceable cla <refsect1 id="sql-do-examples"> <title id="sql-do-examples-title">Examples</title> <para> - Execute a simple PL/pgsql loop without needing to create a function: + Grant all privileges on all views in schema <literal>public</> to + role <literal>webuser</>: <programlisting> -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$$; </programlisting> + This example assumes that <varname>default_do_language</> has its + default value, namely <literal>plpgsql</>. </para> </refsect1> <refsect1> |