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

A request to create a table from column, index and constraint definitions, a query, or both.

Rule: MYSQL-CREATE-TABLE-001. The statement provides one table declaration (MYSQL-TABLE-DECLARATION-001); it executes nothing and changes no context, and neither TEMPORARY nor IF NOT EXISTS changes what it declares (a temporary table hides a permanent table of the same name for the session only). The statement node is the one relation occurrence of the new table: its relation fact resolves to the declaration the statement provides, the same object, and holds its row shape. The query of CREATE TABLE ... SELECT is derived as an independent query that does not see the new table. DEFAULT expressions, generated column expressions, CHECK conditions, functional key parts and the partitioning are derived in the scope of MYSQL-DEFINITION-SCOPE-001, whose only visible relation is that occurrence. MySQL 5.x accepts TEMPORARY written more than once, and a PARTITION BY clause inside the parenthesis that opens the query (MYSQL-ENCLOSED-PARTITIONING-001); both are kept so the statement is written back as it was. Diagnostics: MYSQL-TABLE-PROBLEMS-001. Source: https://dev.mysql.com/doc/refman/8.4/en/create-table.html, https://dev.mysql.com/doc/refman/8.4/en/create-table-select.html, https://dev.mysql.com/doc/refman/8.4/en/create-temporary-table.html. Status: Implemented.

Providing a declaration to a contextdoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TABLE t (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20), note TEXT NULL)');
    $table = $create->declarations()[0];
    [count($table->columns), $table->columns[0]->nullability, $table->columns[2]->nullability] // => [3, \SqlSemantics\Platform\MySql\Model\Statement\Type\Nullability::NotNull, \SqlSemantics\Platform\MySql\Model\Statement\Type\Nullability::Nullable]
The relation fact of the statement resolves to the declaration it providesdoctest
$create = (new \SqlSemantics\Platform\MySql\Semantics())->analyze('CREATE TABLE t (a INT, CHECK (a > 0))');
    $create->facts->scalar($create->statement->elements[1]->condition->left)->resolution->slot->column === $create->declarations()[0]->columns[0] // => true

Properties§

public list<TableElement> $elements
public list<TableOption> $options
public Partitioning|null $partitioning = null
public TableQuery|null $query = null
public int $temporaryWords = 0
public bool $ifNotExists = false
public bool $enclosed = false

Methods§

public function __construct(
    public QualifiedName $name,
    list<TableElement> $elements = [],
    list<TableOption> $options = [],
    public Partitioning|null $partitioning = null,
    public TableQuery|null $query = null,
    public int $temporaryWords = 0,
    public bool $ifNotExists = false,
    public bool $enclosed = false,
)

Parameters

$nameQualifiedNameThe table name
$elementslist<TableElement>The column, index and constraint definitions in order; empty when no list is written
$optionslist<TableOption>The table options in order
$partitioningPartitioning|nullThe PARTITION BY clause
$queryTableQuery|nullThe query whose rows fill the table
$temporaryWordsintHow many times TEMPORARY is written; MySQL 8.0 and later accept it once
$ifNotExistsboolWhether IF NOT EXISTS is written
$enclosedboolWhether the partitioning is written inside the parenthesis that opens the query (MySQL 5.x)
Calls 6
public function temporary(): bool

Tells whether the table is TEMPORARY.

Returns

bool
public function deriveStatement(Derivation $derivation): void

Derives the definition: its declaration, its problems and the expressions inside it.

Parameters

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

Derives the query, provides the declaration and reports the problems of the definition; the fact resolves to that declaration.

Parameters

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

Writes the definition.

Parameters

$outOutput
Calls 8

Test cases 64§

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

Dedicated tests 3
Other tests reaching this symbol 61

Relations§

Instantiated in 4
Type declarations 7