DO
Description
DO executes anonymous code blocks.
A code block is regarded as a function body without parameters. The return value type is void. It is parsed and executed a single time.
Precautions
- Before using a procedural language, you must install it in the current database by running the CREATE LANGUAGE command. PL/pgSQL is installed by default. To install another language, you must specify it.
- To use an untrusted language, you must have the USAGE permission on the programming language or the system administrator permission.
Syntax
DO [ LANGUAGE lang_name ] code;
Parameters
- lang_name
Specifies the name of the procedural language the code is written in. If omitted, the default language is PL/pgSQL.
- code
Specifies the programming language code that can be executed. The value must be a character string.
Examples
-- Create the webuser user. gaussdb=# CREATE USER webuser PASSWORD '********'; -- Grant all permissions on all views in the tpcds schema to the webuser user. gaussdb=# DO $$DECLARE r record; BEGIN FOR r IN SELECT c.relname table_name,n.nspname table_schema 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$$; -- Delete the webuser user. gaussdb=# DROP USER webuser CASCADE;
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.