From e33eeb249e0bcb4ddbb763844024550df3c7bc69 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 23 Sep 2009 15:41:51 +0000 Subject: [PATCH] Improve example for DO, per Petr Jelinek. --- doc/src/sgml/ref/do.sgml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/doc/src/sgml/ref/do.sgml b/doc/src/sgml/ref/do.sgml index 2fb5380663..0a85144726 100644 --- a/doc/src/sgml/ref/do.sgml +++ b/doc/src/sgml/ref/do.sgml @@ -1,5 +1,5 @@ @@ -42,6 +42,11 @@ DO code [ LANGUAGE 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.