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

A request to create a table from the result of a query and fill it with the rows.

Rule: SQLITE-CREATE-TABLE-AS-001. The query is derived as a root query. The statement provides one table declaration whose columns come from the output fields of the query (SQLITE-QUERY-COLUMNS-001); the table has a rowid and no constraints. When the query shape is open or a column name is not determined, the declaration lists the leading determined columns and is marked incomplete. The statement returns no rows. A TEMP table belongs to the temp schema. Source: https://sqlite.org/lang_createtable.html#create_table_as_select_statements. Status: Implemented.

Declaring a table from a querydoctest
$semantics = new \SqlSemantics\Platform\Sqlite\Semantics();
    $source = $semantics->analyze('CREATE TABLE s (a INTEGER, b TEXT)');
    $table = $semantics->analyze('CREATE TABLE t AS SELECT a, b AS label FROM s', [$source])->declarations()[0];
    [$table->columns[0]->type->name(), $table->columns[1]->name->value, $table->complete] // => ['INT', 'label', true]

Properties§

public Query $query
public bool $temporary = false
public bool $ifNotExists = false

Methods§

public function __construct(
    public QualifiedName $name,
    public Query $query,
    public bool $temporary = false,
    public bool $ifNotExists = false,
)

Parameters

$nameQualifiedNameThe table name
$queryQueryThe query whose result defines and fills the table
$temporaryboolWhether TEMP or TEMPORARY is written
$ifNotExistsboolWhether IF NOT EXISTS is written
Calls 1
public function deriveStatement(Derivation $derivation): void

Derives the query and provides the declaration made from its output.

Parameters

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

Writes the definition.

Parameters

$outOutput
Calls 3

Test cases 2§

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

Dedicated tests 1
Other tests reaching this symbol 1

Relations§

Instantiated in 1