final class CreateView
    implements SchemaElement, RecursiveDefinition
    uses Snapshot
Public API: explicitly declared with @visibility public.

A request to create a view.

Mirrors PostgreSQL's ViewStmt (view with its persistence, aliases, query, replace, options, withCheckOption). The statement provides one declaration (PG-QUERY-TABLE-001) whose columns keep the NULL facts of the query. A RECURSIVE view is a view over a recursive common table of the same name and column names; the query sees the view as that common table. A view has no storage, so UNLOGGED is an error. A check option 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-createview.html.

Declaring a viewdoctest
$semantics = new \SqlSemantics\Platform\PostgreSql\Semantics();
    $table = $semantics->analyze('CREATE TABLE t (a int NOT NULL, b text)', []);
    $view = $semantics->analyze('CREATE OR REPLACE VIEW v (x) AS SELECT a, b FROM t', $table->declarations());
    array_map(static fn ($column) => [$column->name->value, $column->nullability->name], $view->declarations()[0]->columns) // => [['x', 'NotNull'], ['b', 'Nullable']]

Properties§

public list<Name> $columns
public list<Definition> $options
public Query&Statement $query
public bool $replace = false
public Persistence $persistence = Persistence::Permanent
public bool $recursive = false
public CheckOption|null $checkOption = null

Methods§

public function __construct(
    public QualifiedName $name,
    public Query&Statement $query,
    list<Name> $columns = [],
    public bool $replace = false,
    public Persistence $persistence = Persistence::Permanent,
    public bool $recursive = false,
    list<Definition> $options = [],
    public CheckOption|null $checkOption = null,
)

Parameters

$nameQualifiedNameThe view name
$queryQuery&StatementThe query
$columnslist<Name>The column names; a recursive view names its columns
$replaceboolWhether OR REPLACE is written
$persistencePersistenceThe persistence
$recursiveboolWhether RECURSIVE is written
$optionslist<Definition>The view options
$checkOptionCheckOption|nullThe check option
Calls 7
public function createdSchema(): ?Name

Answers the schema written on the view name.

Returns

public function recursiveQuery(): Query

Answers the query; for a recursive view, the query of its recursive common table.

Returns

public function recursiveColumns(): list<Name>

Answers the column names.

Returns

list<Name>
public function deriveStatement(Derivation $derivation): void

Derives the query and provides the declaration of the view.

Parameters

$derivationDerivation
Calls 2
public function deriveElement(Derivation $derivation, Name $schema): void

Derives the statement inside CREATE SCHEMA: an unqualified view belongs to that schema.

Parameters

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

Writes the statement.

Parameters

$outOutput
Calls 7

Test cases 4§

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

Dedicated tests 4

Relations§

Instantiated in 1
Constant reads 1
Type declarations 2