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.

Declaring a materialized viewdoctest
$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> $columns
public list<Definition> $options
public Query&Statement $query
public bool $unlogged = false
public bool $ifNotExists = false
public Name|null $method = null
public Name|null $tablespace = null
public bool|null $withData = null

Methods§

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

$nameQualifiedNameThe view name
$queryQuery&StatementThe query
$columnslist<Name>The column names
$unloggedboolWhether UNLOGGED is written
$ifNotExistsboolWhether IF NOT EXISTS is written
$methodName|nullThe table access method
$optionslist<Definition>The storage parameters
$tablespaceName|nullThe tablespace
$withDatabool|nullTrue for WITH DATA, false for WITH NO DATA, null when not written
Calls 6
public function deriveStatement(Derivation $derivation): void

Derives the query and provides the declaration of the view.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 7

Test cases 1§

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

Dedicated tests 1

Relations§

Instantiated in 1
Type declarations 1