1DO(7) PostgreSQL 13.3 Documentation DO(7)
2
3
4
6 DO - execute an anonymous code block
7
9 DO [ LANGUAGE lang_name ] code
10
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
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
32 The procedural language to be used must already have been installed
33 into the current database by means of CREATE EXTENSION. 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
40 If DO is executed in a transaction block, then the procedure code
41 cannot execute transaction control statements. Transaction control
42 statements are only allowed if DO is executed in its own transaction.
43
45 Grant all privileges on all views in schema public to role webuser:
46
47 DO $$DECLARE r record;
48 BEGIN
49 FOR r IN SELECT table_schema, table_name FROM information_schema.tables
50 WHERE table_type = 'VIEW' AND table_schema = 'public'
51 LOOP
52 EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser';
53 END LOOP;
54 END$$;
55
57 There is no DO statement in the SQL standard.
58
60 CREATE LANGUAGE (CREATE_LANGUAGE(7))
61
62
63
64PostgreSQL 13.3 2021 DO(7)