3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "DO" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 DO \- execute an anonymous code block
35 DO [ LANGUAGE \fIlang_name\fR ] \fIcode\fR
40 executes an anonymous code block, or in other words a transient anonymous function in a procedural language\&.
42 The code block is treated as though it were the body of a function with no parameters, returning
43 void\&. It is parsed and executed a single time\&.
47 clause can be written either before or after the code block\&.
52 The procedural language code to be executed\&. This must be specified as a string literal, just as in
53 \fBCREATE FUNCTION\fR\&. Use of a dollar\-quoted literal is recommended\&.
58 The name of the procedural language the code is written in\&. If omitted, the default is
63 The procedural language to be used must already have been installed into the current database by means of
64 \fBCREATE EXTENSION\fR\&.
66 is installed by default, but other languages are not\&.
70 privilege for the procedural language, or must be a superuser if the language is untrusted\&. This is the same privilege requirement as for creating a function in the language\&.
74 is executed in a transaction block, then the procedure code cannot execute transaction control statements\&. Transaction control statements are only allowed if
76 is executed in its own transaction\&.
79 Grant all privileges on all views in schema
88 DO $$DECLARE r record;
90 FOR r IN SELECT table_schema, table_name FROM information_schema\&.tables
91 WHERE table_type = \*(AqVIEW\*(Aq AND table_schema = \*(Aqpublic\*(Aq
93 EXECUTE \*(AqGRANT ALL ON \*(Aq || quote_ident(r\&.table_schema) || \*(Aq\&.\*(Aq || quote_ident(r\&.table_name) || \*(Aq TO webuser\*(Aq;
104 statement in the SQL standard\&.
106 CREATE LANGUAGE (\fBCREATE_LANGUAGE\fR(7))