classCreateView
final class CreateView
implements SchemaElement, RecursiveDefinition
uses Snapshot
@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.
$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> $columnspublic list<Definition> $optionspublic QualifiedName $namepublic bool $replace = falsepublic Persistence $persistence = Persistence::Permanentpublic bool $recursive = falsepublic CheckOption|null $checkOption = nullMethods§
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
$name | QualifiedName | The view name |
$query | Query&Statement | The query |
$columns | list<Name> | The column names; a recursive view names its columns |
$replace | bool | Whether OR REPLACE is written |
$persistence | Persistence | The persistence |
$recursive | bool | Whether RECURSIVE is written |
$options | list<Definition> | The view options |
$checkOption | CheckOption|null | The check option |
Calls 7
- class-const Persistence::Permanent() line 73
- static-call Check::listOf() line 78
- class-const Name::class() line 78
- class-const Definition::class() line 79
- static-call Check::input() line 80
- method-call Trailing::takesWith() line 80
- new Trailing line 80
public function recursiveQuery(): QueryAnswers the query; for a recursive view, the query of its recursive common table.
Returns
public function deriveStatement(Derivation $derivation): voidDerives the query and provides the declaration of the view.
Parameters
$derivation | Derivation |
Calls 2
- method-call Views::derive() line 114
- new Views line 114
public function deriveElement(Derivation $derivation, Name $schema): voidDerives the statement inside CREATE SCHEMA: an unqualified view belongs to that schema.
Parameters
$derivation | Derivation | |
$schema | Name |
Calls 2
- method-call Views::derive() line 122
- new Views line 122
public function render(Output $out): voidWrites the statement.
Parameters
$out | Output |
Calls 7
- method-call Output::keyword() line 130
- method-call Output::node() line 134
- method-call Spelling::qualified() line 139
- new Spelling line 139
- new Writing line 140
- method-call Writing::parenthesized() line 142
- method-call Writing::definitions() line 146
Test cases 4§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.