DO <refpurpose>execute an anonymous code block</refpurpose> — 無名コードブロックを実行する
DO [ LANGUAGElang_name]code
<command>DO</command> executes an anonymous code block, or in other
words a transient anonymous function in a procedural language.
DOは無名コードブロック、言い換えると、手続き言語内の一時的な無名関数を実行します。
The code block is treated as though it were the body of a function
with no parameters, returning <type>void</type>. It is parsed and
executed a single time.
コードブロックはあたかもパラメータを取らずにvoidを返す関数の本体かのように扱われます。
これは解析され、一回実行されます。
The optional <literal>LANGUAGE</literal> clause can be written either
before or after the code block.
LANGUAGE句をコードブロックの前または後ろにつけることができます。
code
The procedural language code to be executed. This must be specified
as a string literal, just as in <command>CREATE FUNCTION</command>.
Use of a dollar-quoted literal is recommended.
実行される手続き言語のコードです。
これは、CREATE FUNCTIONの場合と同様、文字列リテラルとして指定しなければなりません。
ドル記号による引用符付けの使用を勧めます。
lang_name
The name of the procedural language the code is written in.
If omitted, the default is <literal>plpgsql</literal>.
コードの作成に使用する手続き言語の名前です。
省略時のデフォルトはplpgsqlです。
The procedural language to be used must already have been installed
into the current database by means of <command>CREATE EXTENSION</command>.
<literal>plpgsql</literal> is installed by default, but other languages are not.
使用される手続き言語は、CREATE EXTENSIONを使用して現在のデータベースにインストール済みでなければなりません。
plpgsqlはデフォルトでインストールされますが、他の言語はインストールされません。
The user must have <literal>USAGE</literal> 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.
ユーザは手続き言語に対するUSAGE権限を持たなければなりません。
また、言語が信用できない場合はスーパーユーザでなければなりません。
これは、その言語における関数作成に必要な権限と同じです。
If <command>DO</command> is executed in a transaction block, then the
procedure code cannot execute transaction control statements. Transaction
control statements are only allowed if <command>DO</command> is executed in
its own transaction.
DOがトランザクションブロック内で実行された場合、プロシージャコードはトランザクション制御文を実行できません。
DOが自身のトランザクション内で実行された場合にのみ、トランザクション制御文は認められます。
Grant all privileges on all views in schema <literal>public</literal> to
role <literal>webuser</literal>:
スキーマpublic内のすべてのビューに対するすべての権限をロールwebuserに付与します。
DO $$DECLARE r record;
BEGIN
FOR r IN SELECT table_schema, table_name FROM information_schema.tables
WHERE table_type = 'VIEW' AND table_schema = 'public'
LOOP
EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser';
END LOOP;
END$$;
There is no <command>DO</command> statement in the SQL standard.
標準SQLにはDO文はありません。