{
    "content": [
        {
            "type": "text",
            "text": "# DO (man)\n\n## NAME\n\nDO - execute an anonymous code block\n\n## SYNOPSIS\n\nDO [ LANGUAGE langname ] code\n\n## DESCRIPTION\n\nDO executes an anonymous code block, or in other words a transient anonymous function in a\nprocedural language.\n\n## TLDR\n\n> This shell keyword is used with `for`, `while`, `select`, and `until` to mark the start of a loop.\n\n- View documentation for the `for` keyword:\n  `tldr for`\n- View documentation for the `while` keyword:\n  `tldr while`\n- View documentation for the `select` keyword:\n  `tldr select`\n- View documentation for the `until` keyword:\n  `tldr until`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **NOTES**\n- **EXAMPLES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "DO",
        "section": "",
        "mode": "man",
        "summary": "DO - execute an anonymous code block",
        "synopsis": "DO [ LANGUAGE langname ] code",
        "tldr_summary": "This shell keyword is used with `for`, `while`, `select`, and `until` to mark the start of a loop.",
        "tldr_examples": [
            {
                "description": "View documentation for the `for` keyword",
                "command": "tldr for"
            },
            {
                "description": "View documentation for the `while` keyword",
                "command": "tldr while"
            },
            {
                "description": "View documentation for the `select` keyword",
                "command": "tldr select"
            },
            {
                "description": "View documentation for the `until` keyword",
                "command": "tldr until"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [
            "Grant all privileges on all views in schema public to role webuser:",
            "DO $$DECLARE r record;",
            "BEGIN",
            "FOR r IN SELECT tableschema, tablename FROM informationschema.tables",
            "WHERE tabletype = 'VIEW' AND tableschema = 'public'",
            "LOOP",
            "EXECUTE 'GRANT ALL ON ' || quoteident(r.tableschema) || '.' || quoteident(r.tablename) || ' TO webuser';",
            "END LOOP;",
            "END$$;"
        ],
        "see_also": [
            {
                "name": "CREATELANGUAGE",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/CREATELANGUAGE/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "DO - execute an anonymous code block\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "DO [ LANGUAGE langname ] code\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "DO executes an anonymous code block, or in other words a transient anonymous function in a\nprocedural language.\n\nThe code block is treated as though it were the body of a function with no parameters,\nreturning void. It is parsed and executed a single time.\n\nThe optional LANGUAGE clause can be written either before or after the code block.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "code\nThe procedural language code to be executed. This must be specified as a string literal,\njust as in CREATE FUNCTION. Use of a dollar-quoted literal is recommended.\n\nlangname\nThe name of the procedural language the code is written in. If omitted, the default is\nplpgsql.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "The procedural language to be used must already have been installed into the current database\nby means of CREATE EXTENSION.  plpgsql is installed by default, but other languages are not.\n\nThe user must have USAGE privilege for the procedural language, or must be a superuser if the\nlanguage is untrusted. This is the same privilege requirement as for creating a function in\nthe language.\n\nIf DO is executed in a transaction block, then the procedure code cannot execute transaction\ncontrol statements. Transaction control statements are only allowed if DO is executed in its\nown transaction.\n",
                "subsections": []
            },
            "EXAMPLES": {
                "content": "Grant all privileges on all views in schema public to role webuser:\n\nDO $$DECLARE r record;\nBEGIN\nFOR r IN SELECT tableschema, tablename FROM informationschema.tables\nWHERE tabletype = 'VIEW' AND tableschema = 'public'\nLOOP\nEXECUTE 'GRANT ALL ON ' || quoteident(r.tableschema) || '.' || quoteident(r.tablename) || ' TO webuser';\nEND LOOP;\nEND$$;\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "There is no DO statement in the SQL standard.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "CREATE LANGUAGE (CREATELANGUAGE(7))\n\n\n\nPostgreSQL 14.23                                2026                                           DO(7)",
                "subsections": []
            }
        }
    }
}