final class DerivedTable
    implements Relation
    uses Snapshot
Public API: explicitly declared with @visibility public.

A subquery in FROM, optionally LATERAL and renamed.

Mirrors PostgreSQL's RangeSubselect. Rule: PG-DERIVED-TABLE-001. The query is derived in the environment the FROM clause gives it: the enclosing query, and, when LATERAL is written, the FROM items before it. The occurrence has one column per output column of the query, renamed by the column aliases; the query writes the parentheses it is enclosed in. Source: https://www.postgresql.org/docs/17/sql-select.html#SQL-FROM, https://www.postgresql.org/docs/17/queries-table-expressions.html#QUERIES-SUBQUERIES. Status: Implemented.

Reading a derived tabledoctest
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT x.b FROM (SELECT 1 AS a) AS x (b)');
    [$query->statement->from->alias->value, $query->field(0)->type->descriptor->name()] // => ['x', 'integer']

Properties§

public list<Name> $columns
public Query $query
public Name|null $alias = null
public bool $lateral = false

Methods§

public function __construct(
    public Query $query,
    public Name|null $alias = null,
    list<Name> $columns = [],
    public bool $lateral = false,
)

Parameters

$queryQueryThe query inside the parentheses
$aliasName|nullThe correlation name
$columnslist<Name>The column names written after the correlation name
$lateralboolWhether the query may refer to the FROM items before it
Calls 3
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFact

Derives the query and the columns of the occurrence.

Parameters

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

Writes LATERAL, the query in parentheses and the alias.

Parameters

$outOutput
Calls 4

Test cases 2§

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

Dedicated tests 1
Other tests reaching this symbol 1

Relations§

Instantiated in 1
Type checks 3
Type declarations 1