final class CreateSchema
    implements Statement
    uses Snapshot
Public API: explicitly declared with @visibility public.

A request to create a schema, optionally with the objects created in it.

Rule: PG-SCHEMA-001. Mirrors CreateSchemaStmt: schema name (the owner's name when only AUTHORIZATION is written), owner, IF NOT EXISTS and the schema elements (CREATE TABLE, CREATE INDEX, CREATE SEQUENCE, CREATE TRIGGER, CREATE VIEW and GRANT) in the order written. IF NOT EXISTS with elements and a name starting with pg_ are diagnostics. The schema is the written name, or the name of the role written after AUTHORIZATION. Each CREATE element is derived as an element of that schema: an unqualified object it creates is declared in the new schema, and an object qualified with another schema is a diagnostic. When the schema name is not written (AUTHORIZATION CURRENT_USER and the like), it depends on the session, so the elements keep their facts and diagnostics but declare nothing. Every element is read with the new schema searched first and sees the relations of the elements the server runs before it (PG-SCHEMA-ELEMENT-001). Source: https://www.postgresql.org/docs/17/sql-createschema.html. Status: Implemented.

Creating a schema for a roledoctest
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE SCHEMA IF NOT EXISTS AUTHORIZATION joe');
    [$operation->statement->name, $operation->statement->authorization?->name?->value] // => [null, 'joe']
Declaring a table in the new schemadoctest
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE SCHEMA AUTHORIZATION joe CREATE TABLE t (a int4)');
    $operation->declarations()[0]->name->schema?->value // => 'joe'

Properties§

public list<Statement> $elements
public Name|null $name
public RoleSpec|null $authorization = null
public bool $ifNotExists = false

Methods§

public function __construct(
    public Name|null $name,
    public RoleSpec|null $authorization = null,
    list<Statement> $elements = [],
    public bool $ifNotExists = false,
)

Parameters

$nameName|nullThe schema name; null when only AUTHORIZATION is written
$authorizationRoleSpec|nullThe owner, when AUTHORIZATION is written
$elementslist<Statement>The schema elements in the order written
$ifNotExistsboolWhether IF NOT EXISTS is written
Calls 3
public function deriveStatement(Derivation $derivation): void

Derives the elements and reports the problems of the request.

Parameters

$derivationDerivation
Calls 13
public function render(Output $out): void

Writes the request.

Parameters

$outOutput
Calls 4

Test cases 1§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 1

Relations§

Instantiated in 4