classCreateMaterializedView
final class CreateMaterializedView
implements Statement
uses Snapshot
Public API: explicitly declared with
@visibility public.A request to create a materialized view: a table that holds the rows of a query until it is refreshed.
Mirrors PostgreSQL's CreateTableAsStmt with objtype MATVIEW. The statement provides one declaration (PG-QUERY-TABLE-001) whose columns keep the NULL facts of the query, 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-creatematerializedview.html.
$create = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('CREATE UNLOGGED MATERIALIZED VIEW IF NOT EXISTS m (n) USING heap WITH (fillfactor = 70) TABLESPACE s AS SELECT 1 WITH NO DATA');
[$create->declarations()[0]->columns[0]->nullability, $create->toString()] // => [\SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability::NotNull, 'CREATE UNLOGGED MATERIALIZED VIEW IF NOT EXISTS m (n) USING heap WITH (fillfactor = 70) TABLESPACE s AS SELECT 1 WITH NO DATA']Properties§
public list<Name> $columnspublic list<Definition> $optionspublic QualifiedName $namepublic bool $unlogged = falsepublic bool $ifNotExists = falsepublic Name|null $method = nullpublic Name|null $tablespace = nullpublic bool|null $withData = nullMethods§
public function __construct(
public QualifiedName $name,
public Query&Statement $query,
list<Name> $columns = [],
public bool $unlogged = false,
public bool $ifNotExists = false,
public Name|null $method = null,
list<Definition> $options = [],
public Name|null $tablespace = null,
public bool|null $withData = null,
)Parameters
$name | QualifiedName | The view name |
$query | Query&Statement | The query |
$columns | list<Name> | The column names |
$unlogged | bool | Whether UNLOGGED is written |
$ifNotExists | bool | Whether IF NOT EXISTS is written |
$method | Name|null | The table access method |
$options | list<Definition> | The storage parameters |
$tablespace | Name|null | The tablespace |
$withData | bool|null | True for WITH DATA, false for WITH NO DATA, null when not written |
Calls 6
- static-call Check::listOf() line 75
- class-const Name::class() line 75
- class-const Definition::class() line 76
- static-call Check::input() line 77
- method-call Trailing::takesWith() line 77
- new Trailing line 77
public function deriveStatement(Derivation $derivation): voidDerives the query and provides the declaration of the view.
Parameters
$derivation | Derivation |
Calls 11
- method-call Derivation::query() line 85
- method-call Derivation::environment() line 85
- new QueryTables line 86
- method-call CreationSchemas::check() line 87
- new CreationSchemas line 87
- class-const Persistence::Unlogged() line 87
- class-const Persistence::Permanent() line 87
- method-call Derivation::declare() line 88
- method-call QueryTables::table() line 88
- method-call QueryTables::name() line 88
- class-const RelationKind::MaterializedView() line 88
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 7
- method-call Output::keyword() line 96
- method-call Spelling::qualified() line 104
- new Spelling line 104
- new Writing line 105
- method-call Writing::parenthesized() line 107
- method-call Writing::definitions() line 114
- method-call Writing::withData() line 120
Test cases 1§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.