YMatrix
Cluster Deployment
Data Model
Data Writing
Data Query
SQL Reference
Maintenance and Monitoring
Tool Guide
Troubleshooting
Define a new pattern.
CREATE SCHEMA schema_name [AUTHORIZATION username]
[schema_element [ ... ]]
CREATE SCHEMA AUTHORIZATION rolename [schema_element [ ... ]]
CREATE SCHEMA IF NOT EXISTS schema_name [ AUTHORIZATION user_name ]
CREATE SCHEMA IF NOT EXISTS AUTHORIZATION user_name
CREATE SCHEMA adds the new schema to the current database. The schema name must be different from the name of any existing schema in the current database.
A schema is essentially a namespace: it contains named objects (tables, data types, functions, and operators) whose names may be repeated with the names of other objects present in other schemas. Named objects can be accessed by qualifying their name with a schema name as a prefix, or by setting a search path containing the desired schema.
(Optional) CREATE SCHEMA can include subcommands to create objects in the new schema. The subcommand is basically the same as the separate commands issued after the pattern is created, the difference is that if the AUTHORIZATION clause is used, all created objects will belong to the role.
schema_name
user_name
schema_element
IF NOT EXISTS
To create a schema, the calling user must have CREATE privileges for the current database, or must be a superuser.
Create a schema:
CREATE SCHEMA myschema;
Create a pattern for the role joe (this pattern will also be named joe):
CREATE SCHEMA AUTHORIZATION joe;
Create a schema called test, which will be owned by user joe unless there is already a schema called test. (It has no effect on whether joe has a pre-existing pattern.)
CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe;
The SQL standard allows the use of the DEFAULT CHARACTER SET clause in CREATE SCHEMA, as well as more subcommand types than the currently accepted subcommand types in YMatrix databases.
SQL standard specifies that subcommands in CREATE SCHEMA can appear in any order. The current YMatrix database implementation does not handle all forward references in subcommands; sometimes it may be necessary to reorder the subcommands to avoid forward references.
According to the SQL standard, the owner of the schema always owns all the objects in it. The YMatrix database allows schemas to contain objects owned by users other than the schema owner. This happens only if the schema owner grants the schema CREATE privilege to others, or if the superuser chooses to create an object there.
The IF NOT EXISTS option is a YMatrix database extension.