classCreateTableAs
final class CreateTableAs
implements Statement
uses Snapshot
@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.
$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 QualifiedName $namepublic Query $querypublic bool $temporary = falsepublic bool $ifNotExists = falseMethods§
public function __construct(
public QualifiedName $name,
public Query $query,
public bool $temporary = false,
public bool $ifNotExists = false,
)Parameters
$name | QualifiedName | The table name |
$query | Query | The query whose result defines and fills the table |
$temporary | bool | Whether TEMP or TEMPORARY is written |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
Calls 1
- static-call Check::input() line 56
public function deriveStatement(Derivation $derivation): voidDerives the query and provides the declaration made from its output.
Parameters
$derivation | Derivation |
Calls 13
- method-call TableProblems::temporary() line 64
- new TableProblems line 64
- method-call Derivation::query() line 65
- method-call Derivation::environment() line 65
- method-call QueryColumns::tableColumns() line 66
- new QueryColumns line 66
- method-call Derivation::facts() line 66
- new TableDeclaration line 67
- method-call Derivation::declare() line 68
- new Table line 68
- method-call TableDeclaration::name() line 69
- method-call TableDeclaration::rowid() line 72
- function-call
countline 73
public function render(Output $out): voidWrites the definition.
Parameters
$out | Output |
Calls 3
- method-call Output::keyword() line 82
- method-call ObjectNames::write() line 90
- new ObjectNames line 90
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.