classCreateTableAs
final class CreateTableAs
implements Statement
uses Snapshot
@visibility public.A request to create a table from the rows of a query.
Mirrors PostgreSQL's CreateTableAsStmt with objtype TABLE (query, into, if_not_exists) and skipData (WITH [NO] DATA). The statement provides one declaration (PG-QUERY-TABLE-001): a column per output column of the query, renamed by the written column names, able to be NULL, with the system columns. WITH [NO] DATA after a query that ends with an IS JSON test without a uniqueness clause is rejected: the test would take the WITH (PG-QUERY-TRAILING-001). Source: https://www.postgresql.org/docs/17/sql-createtableas.html.
$create = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze("CREATE TEMP TABLE t (n) AS SELECT 1, 'x' AS s WITH NO DATA");
$table = $create->declarations()[0];
[$table->name->schema->value, array_map(static fn ($column) => $column->name->value . ' ' . $column->type->name(), $table->columns)] // => ['pg_temp', ['n integer', 's text']]Properties§
public CreateTarget $targetpublic Persistence $persistence = Persistence::Permanentpublic bool $ifNotExists = falsepublic bool|null $withData = nullMethods§
public function __construct(
public CreateTarget $target,
public Query&Statement $query,
public Persistence $persistence = Persistence::Permanent,
public bool $ifNotExists = false,
public bool|null $withData = null,
)Parameters
$target | CreateTarget | The new table |
$query | Query&Statement | The query |
$persistence | Persistence | The persistence |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
$withData | bool|null | True for WITH DATA, false for WITH NO DATA, null when not written |
Calls 4
- class-const Persistence::Permanent() line 51
- static-call Check::input() line 55
- method-call Trailing::takesWith() line 55
- new Trailing line 55
public function deriveStatement(Derivation $derivation): voidDerives the query and provides the declaration of its table.
Parameters
$derivation | Derivation |
Calls 9
- method-call Derivation::query() line 63
- method-call Derivation::environment() line 63
- new QueryTables line 64
- method-call CreationSchemas::check() line 65
- new CreationSchemas line 65
- method-call Derivation::declare() line 66
- method-call QueryTables::table() line 66
- method-call QueryTables::name() line 66
- class-const RelationKind::BaseTable() line 66
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 74
- method-call Output::node() line 78
- method-call Writing::withData() line 79
- new Writing line 79
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.