DO
Description
Executes an anonymous code block.
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
- The procedural language to be used must already have been installed into the current database by means of CREATE LANGUAGE. PL/pgSQL is installed by default, but other languages are not.
- To use an untrusted language, you must have the USAGE permission on the programming language or the SYSADMIN permission.
Syntax
1
|
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
-- Create the webuser user. openGauss=# CREATE USER webuser PASSWORD '********'; -- Grant all permissions on all views in the tpcds schema to the webuser user. openGauss=# 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$$; -- Drop the webuser user. openGauss=# 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.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot