classCreateSchema
final class CreateSchema
implements Statement
uses Snapshot
@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.
$operation = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE SCHEMA IF NOT EXISTS AUTHORIZATION joe');
[$operation->statement->name, $operation->statement->authorization?->name?->value] // => [null, 'joe']$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> $elementspublic Name|null $namepublic RoleSpec|null $authorization = nullpublic bool $ifNotExists = falseMethods§
public function __construct(
public Name|null $name,
public RoleSpec|null $authorization = null,
list<Statement> $elements = [],
public bool $ifNotExists = false,
)Parameters
Calls 3
- static-call Check::listOf() line 64
- class-const Statement::class() line 64
- static-call Check::input() line 65
public function deriveStatement(Derivation $derivation): voidDerives the elements and reports the problems of the request.
Parameters
$derivation | Derivation |
Calls 13
- method-call Derivation::report() line 74
- new CatalogMisuse line 74
- class-const CatalogMisuseRule::SchemaElementsIfNotExists() line 74
- function-call
str_starts_withline 76 - class-const CatalogMisuseRule::ReservedSchemaName() line 77
- method-call Derivation::inspected() line 83
- method-call Derivation::statement() line 83
- class-const CatalogMisuseRule::ElementSchemaMismatch() line 88
- new SchemaMember line 90
- function-call
usortline 92 - method-call SchemaMember::step() line 92
- method-call Derivation::within() line 94
- method-call Derivation::facts() line 94
public function render(Output $out): voidWrites the request.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 103
- method-call Output::name() line 108
- class-const NameUse::Column() line 108
- method-call Output::node() line 114
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
- new SqlSemantics\Platform\PostgreSql\Lowering\Catalog\SchemaRule::statement() packages/sql-semantics-postgres/src/Lowering/Catalog/SchemaRule.php:52
- new SqlSemantics\Platform\PostgreSql\Lowering\Catalog\SchemaRule::statement() packages/sql-semantics-postgres/src/Lowering/Catalog/SchemaRule.php:53
- new SqlSemantics\Platform\PostgreSql\Lowering\Catalog\SchemaRule::statement() packages/sql-semantics-postgres/src/Lowering/Catalog/SchemaRule.php:54
- new SqlSemantics\Platform\PostgreSql\Lowering\Catalog\SchemaRule::statement() packages/sql-semantics-postgres/src/Lowering/Catalog/SchemaRule.php:55