1DO(7)                   PostgreSQL 9.2.24 Documentation                  DO(7)
2
3
4

NAME

6       DO - execute an anonymous code block
7

SYNOPSIS

9       DO [ LANGUAGE lang_name ] code
10

DESCRIPTION

12       DO executes an anonymous code block, or in other words a transient
13       anonymous function in a procedural language.
14
15       The code block is treated as though it were the body of a function with
16       no parameters, returning void. It is parsed and executed a single time.
17
18       The optional LANGUAGE clause can be written either before or after the
19       code block.
20

PARAMETERS

22       code
23           The procedural language code to be executed. This must be specified
24           as a string literal, just as in CREATE FUNCTION. Use of a
25           dollar-quoted literal is recommended.
26
27       lang_name
28           The name of the procedural language the code is written in. If
29           omitted, the default is plpgsql.
30

NOTES

32       The procedural language to be used must already have been installed
33       into the current database by means of CREATE LANGUAGE.  plpgsql is
34       installed by default, but other languages are not.
35
36       The user must have USAGE privilege for the procedural language, or must
37       be a superuser if the language is untrusted. This is the same privilege
38       requirement as for creating a function in the language.
39

EXAMPLES

41       Grant all privileges on all views in schema public to role webuser:
42
43           DO $$DECLARE r record;
44           BEGIN
45               FOR r IN SELECT table_schema, table_name FROM information_schema.tables
46                        WHERE table_type = 'VIEW' AND table_schema = 'public'
47               LOOP
48                   EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser';
49               END LOOP;
50           END$$;
51

COMPATIBILITY

53       There is no DO statement in the SQL standard.
54

SEE ALSO

56       CREATE LANGUAGE (CREATE_LANGUAGE(7))
57
58
59
60PostgreSQL 9.2.24                 2017-11-06                             DO(7)
Impressum