final class CreateTable
    implements SchemaElement, Relation
    uses Snapshot
Public API: explicitly declared with @visibility public.

A request to create a table.

Mirrors PostgreSQL's CreateStmt (relation with its persistence, tableElts/inhRelations, ofTypename or partbound, partspec, accessMethod, options, oncommit, tablespacename, if_not_exists). The statement provides one declaration (PG-TABLE-DECLARATION-001) and is the one relation occurrence of the new table: its relation fact resolves to that declaration. The expressions of the definition are derived where that table is the only visible relation (PG-TABLE-DEFINITION-001). The optional WITHOUT OIDS clause is a no-op and is not kept. Source: https://www.postgresql.org/docs/17/sql-createtable.html.

Providing a declaration to a contextdoctest
$semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
    $create = $semantics->analyze('CREATE TABLE app.t (id serial PRIMARY KEY, name varchar(20) NOT NULL, note text)', []);
    $table = $create->declarations()[0];
    [array_map(static fn ($column) => $column->type->name(), $table->columns), $table->columns[2]->nullability, $table->implicit[0]->names[0]->value] // => [['integer', 'character varying(20)', 'text'], \SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability::Nullable, 'tableoid']

Properties§

public list<Definition> $options
public TableForm $definition
public Persistence $persistence = Persistence::Permanent
public bool $ifNotExists = false
public PartitionSpec|null $partitioning = null
public Name|null $method = null
public OnCommit|null $onCommit = null
public Name|null $tablespace = null

Methods§

public function __construct(
    public QualifiedName $name,
    public TableForm $definition,
    public Persistence $persistence = Persistence::Permanent,
    public bool $ifNotExists = false,
    public PartitionSpec|null $partitioning = null,
    public Name|null $method = null,
    list<Definition> $options = [],
    public OnCommit|null $onCommit = null,
    public Name|null $tablespace = null,
)

Parameters

$nameQualifiedNameThe table name
$definitionTableFormThe columns: a column list, a composite type or a parent partitioned table
$persistencePersistenceThe persistence
$ifNotExistsboolWhether IF NOT EXISTS is written
$partitioningPartitionSpec|nullThe PARTITION BY clause
$methodName|nullThe table access method
$optionslist<Definition>The storage parameters
$onCommitOnCommit|nullThe ON COMMIT action
$tablespaceName|nullThe tablespace
Calls 3
public function createdSchema(): ?Name

Answers the schema written on the table name.

Returns

public function deriveStatement(Derivation $derivation): void

Provides the declaration and derives the definition against it.

Parameters

$derivationDerivation
Calls 2
public function deriveElement(Derivation $derivation, Name $schema): void

Derives the statement inside CREATE SCHEMA: an unqualified table belongs to that schema.

Parameters

$derivationDerivation
$schemaName
Calls 2
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Answers the facts of the new table: its row shape and the declaration, without providing it.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 6

Test cases 31§

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

Dedicated tests 2
Other tests reaching this symbol 29

Relations§

Instantiated in 1
Constant reads 1
Type checks 3
Type declarations 5