DO

Function

DO executes an anonymous code block.

A code block is a function body without parameters that returns void. It is analyzed and executed at the same time.

Precautions

Syntax

1
DO [ LANGUAGE lang_name ] code;

Parameter Description

Examples

Grant user webuser all the operation permissions on views in the tpcds schema.
1
2
3
4
5
6
7
8
DO $$DECLARE r record;
BEGIN
    FOR r IN SELECT c.relname,n.nspname FROM pg_class c,pg_namespace n 
             WHERE c.relnamespace = n.oid AND n.nspname = 'tpcds' AND relkind IN ('r','v')
    LOOP
        EXECUTE 'GRANT ALL ON ' || quote_ident(r.table_schema) || '.' || quote_ident(r.table_name) || ' TO webuser';
    END LOOP;
END$$;