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

One common table expression: a name, optional column names, and the statement that computes its rows.

Mirrors PostgreSQL's CommonTableExpr. The statement is a query or a data-modifying statement, whose rows are its RETURNING list. The WITH clause that holds the expression binds it (PG-COMMON-TABLE-001). Source: https://www.postgresql.org/docs/17/queries-with.html.

Reading a common table expressiondoctest
$one = new \SqlSemantics\Platform\PostgreSql\Statement\Query\Select([new \SqlSemantics\Platform\PostgreSql\Statement\Query\ExpressionTarget(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('1')))]);
    $table = new \SqlSemantics\Platform\PostgreSql\Statement\Query\With\CommonTableExpression(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('x'), $one, [new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('a')], \SqlSemantics\Platform\PostgreSql\Statement\Query\With\Materialization::Materialized);
    [$table->name->value, $table->columns[0]->value, $table->materialization->value] // => ['x', 'a', 'MATERIALIZED']

Properties§

public list<Name> $columns
public Name $name
public Query $query
public Materialization|null $materialization = null
public SearchClause|null $search = null
public CycleClause|null $cycle = null

Methods§

public function __construct(
    public Name $name,
    public Query $query,
    list<Name> $columns = [],
    public Materialization|null $materialization = null,
    public SearchClause|null $search = null,
    public CycleClause|null $cycle = null,
)

Parameters

$nameNameThe name the statement refers to the table by
$queryQueryThe query or data-modifying statement that computes the rows
$columnslist<Name>The column names written after the name
$materializationMaterialization|nullWhether the rows are computed once, as written
$searchSearchClause|nullThe SEARCH clause of a recursive query
$cycleCycleClause|nullThe CYCLE clause of a recursive query
Calls 3
public function recursiveQuery(): Query
public function recursiveColumns(): list<Name>
public function render(Output $out): void

Writes the name, the columns, AS, the materialization, the statement in parentheses and the SEARCH and CYCLE clauses.

Parameters

$outOutput
Test cases 1
Calls 5

Test cases 16§

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

Dedicated tests 3
Other tests reaching this symbol 13

Relations§

Instantiated in 1
Constant reads 1
Type checks 1
Type declarations 4