{
    "content": [
        {
            "type": "text",
            "text": "# CREATE_SCHEMA(7) (man)\n\n**Summary:** CREATESCHEMA - define a new schema\n\n**Synopsis:** CREATE SCHEMA schemaname [ AUTHORIZATION rolespecification ] [ schemaelement [ ... ] ]\nCREATE SCHEMA AUTHORIZATION rolespecification [ schemaelement [ ... ] ]\nCREATE SCHEMA IF NOT EXISTS schemaname [ AUTHORIZATION rolespecification ]\nCREATE SCHEMA IF NOT EXISTS AUTHORIZATION rolespecification\nwhere rolespecification can be:\nusername\n| CURRENTROLE\n| CURRENTUSER\n| SESSIONUSER\n\n## Examples\n\n- `Create a schema:`\n- `CREATE SCHEMA myschema;`\n- `Create a schema for user joe; the schema will also be named joe:`\n- `CREATE SCHEMA AUTHORIZATION joe;`\n- `Create a schema named test that will be owned by user joe, unless there already is a schema`\n- `named test. (It does not matter whether joe owns the pre-existing schema.)`\n- `CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe;`\n- `Create a schema and create a table and view within it:`\n- `CREATE SCHEMA hollywood`\n- `CREATE TABLE films (title text, release date, awards text[])`\n- `CREATE VIEW winners AS`\n- `SELECT title, release FROM films WHERE awards IS NOT NULL;`\n- `Notice that the individual subcommands do not end with semicolons.`\n- `The following is an equivalent way of accomplishing the same result:`\n- `CREATE SCHEMA hollywood;`\n- `CREATE TABLE hollywood.films (title text, release date, awards text[]);`\n- `CREATE VIEW hollywood.winners AS`\n- `SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;`\n\n## See Also\n\n- ALTERSCHEMA(7)\n- DROPSCHEMA(7)\n- SCHEMA(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (12 lines)\n- **DESCRIPTION** (16 lines)\n- **PARAMETERS** (20 lines)\n- **NOTES** (3 lines)\n- **EXAMPLES** (29 lines)\n- **COMPATIBILITY** (15 lines)\n- **SEE ALSO** (5 lines)\n\n## Full Content\n\n### NAME\n\nCREATESCHEMA - define a new schema\n\n### SYNOPSIS\n\nCREATE SCHEMA schemaname [ AUTHORIZATION rolespecification ] [ schemaelement [ ... ] ]\nCREATE SCHEMA AUTHORIZATION rolespecification [ schemaelement [ ... ] ]\nCREATE SCHEMA IF NOT EXISTS schemaname [ AUTHORIZATION rolespecification ]\nCREATE SCHEMA IF NOT EXISTS AUTHORIZATION rolespecification\n\nwhere rolespecification can be:\n\nusername\n| CURRENTROLE\n| CURRENTUSER\n| SESSIONUSER\n\n### DESCRIPTION\n\nCREATE SCHEMA enters a new schema into the current database. The schema name must be distinct\nfrom the name of any existing schema in the current database.\n\nA schema is essentially a namespace: it contains named objects (tables, data types,\nfunctions, and operators) whose names can duplicate those of other objects existing in other\nschemas. Named objects are accessed either by “qualifying” their names with the schema name\nas a prefix, or by setting a search path that includes the desired schema(s). A CREATE\ncommand specifying an unqualified object name creates the object in the current schema (the\none at the front of the search path, which can be determined with the function\ncurrentschema).\n\nOptionally, CREATE SCHEMA can include subcommands to create objects within the new schema.\nThe subcommands are treated essentially the same as separate commands issued after creating\nthe schema, except that if the AUTHORIZATION clause is used, all the created objects will be\nowned by that user.\n\n### PARAMETERS\n\nschemaname\nThe name of a schema to be created. If this is omitted, the username is used as the\nschema name. The name cannot begin with pg, as such names are reserved for system\nschemas.\n\nusername\nThe role name of the user who will own the new schema. If omitted, defaults to the user\nexecuting the command. To create a schema owned by another role, you must be a direct or\nindirect member of that role, or be a superuser.\n\nschemaelement\nAn SQL statement defining an object to be created within the schema. Currently, only\nCREATE TABLE, CREATE VIEW, CREATE INDEX, CREATE SEQUENCE, CREATE TRIGGER and GRANT are\naccepted as clauses within CREATE SCHEMA. Other kinds of objects may be created in\nseparate commands after the schema is created.\n\nIF NOT EXISTS\nDo nothing (except issuing a notice) if a schema with the same name already exists.\nschemaelement subcommands cannot be included when this option is used.\n\n### NOTES\n\nTo create a schema, the invoking user must have the CREATE privilege for the current\ndatabase. (Of course, superusers bypass this check.)\n\n### EXAMPLES\n\nCreate a schema:\n\nCREATE SCHEMA myschema;\n\nCreate a schema for user joe; the schema will also be named joe:\n\nCREATE SCHEMA AUTHORIZATION joe;\n\nCreate a schema named test that will be owned by user joe, unless there already is a schema\nnamed test. (It does not matter whether joe owns the pre-existing schema.)\n\nCREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe;\n\nCreate a schema and create a table and view within it:\n\nCREATE SCHEMA hollywood\nCREATE TABLE films (title text, release date, awards text[])\nCREATE VIEW winners AS\nSELECT title, release FROM films WHERE awards IS NOT NULL;\n\nNotice that the individual subcommands do not end with semicolons.\n\nThe following is an equivalent way of accomplishing the same result:\n\nCREATE SCHEMA hollywood;\nCREATE TABLE hollywood.films (title text, release date, awards text[]);\nCREATE VIEW hollywood.winners AS\nSELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;\n\n### COMPATIBILITY\n\nThe SQL standard allows a DEFAULT CHARACTER SET clause in CREATE SCHEMA, as well as more\nsubcommand types than are presently accepted by PostgreSQL.\n\nThe SQL standard specifies that the subcommands in CREATE SCHEMA can appear in any order. The\npresent PostgreSQL implementation does not handle all cases of forward references in\nsubcommands; it might sometimes be necessary to reorder the subcommands in order to avoid\nforward references.\n\nAccording to the SQL standard, the owner of a schema always owns all objects within it.\nPostgreSQL allows schemas to contain objects owned by users other than the schema owner. This\ncan happen only if the schema owner grants the CREATE privilege on their schema to someone\nelse, or a superuser chooses to create objects in it.\n\nThe IF NOT EXISTS option is a PostgreSQL extension.\n\n### SEE ALSO\n\nALTER SCHEMA (ALTERSCHEMA(7)), DROP SCHEMA (DROPSCHEMA(7))\n\n\n\nPostgreSQL 14.23                                2026                                CREATE SCHEMA(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "CREATE_SCHEMA",
        "section": "7",
        "mode": "man",
        "summary": "CREATESCHEMA - define a new schema",
        "synopsis": "CREATE SCHEMA schemaname [ AUTHORIZATION rolespecification ] [ schemaelement [ ... ] ]\nCREATE SCHEMA AUTHORIZATION rolespecification [ schemaelement [ ... ] ]\nCREATE SCHEMA IF NOT EXISTS schemaname [ AUTHORIZATION rolespecification ]\nCREATE SCHEMA IF NOT EXISTS AUTHORIZATION rolespecification\nwhere rolespecification can be:\nusername\n| CURRENTROLE\n| CURRENTUSER\n| SESSIONUSER",
        "flags": [],
        "examples": [
            "Create a schema:",
            "CREATE SCHEMA myschema;",
            "Create a schema for user joe; the schema will also be named joe:",
            "CREATE SCHEMA AUTHORIZATION joe;",
            "Create a schema named test that will be owned by user joe, unless there already is a schema",
            "named test. (It does not matter whether joe owns the pre-existing schema.)",
            "CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe;",
            "Create a schema and create a table and view within it:",
            "CREATE SCHEMA hollywood",
            "CREATE TABLE films (title text, release date, awards text[])",
            "CREATE VIEW winners AS",
            "SELECT title, release FROM films WHERE awards IS NOT NULL;",
            "Notice that the individual subcommands do not end with semicolons.",
            "The following is an equivalent way of accomplishing the same result:",
            "CREATE SCHEMA hollywood;",
            "CREATE TABLE hollywood.films (title text, release date, awards text[]);",
            "CREATE VIEW hollywood.winners AS",
            "SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;"
        ],
        "see_also": [
            {
                "name": "ALTERSCHEMA",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/ALTERSCHEMA/7/json"
            },
            {
                "name": "DROPSCHEMA",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/DROPSCHEMA/7/json"
            },
            {
                "name": "SCHEMA",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/SCHEMA/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 29,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 15,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ]
    }
}