classDerivedTable
final class DerivedTable
implements Relation
uses Snapshot
@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.
$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> $columnspublic Query $querypublic Name|null $alias = nullpublic bool $lateral = falseMethods§
public function __construct(
public Query $query,
public Name|null $alias = null,
list<Name> $columns = [],
public bool $lateral = false,
)Parameters
Calls 3
- static-call Check::listOf() line 52
- class-const Name::class() line 52
- static-call Check::input() line 53
public function deriveRelation(Derivation $derivation, Environment $environment): RelationFactDerives the query and the columns of the occurrence.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 5
- method-call Derivation::query() line 61
- new RelationFact line 63
- method-call ColumnAliases::apply() line 63
- new ColumnAliases line 63
- method-call ColumnAliases::fromQuery() line 63
public function render(Output $out): voidWrites LATERAL, the query in parentheses and the alias.
Parameters
$out | Output |
Calls 4
- method-call Output::keyword() line 72
- method-call Output::symbol() line 74
- method-call AliasSpelling::write() line 75
- new AliasSpelling line 75
Test cases 2§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 1
DerivedTableTestcalls
Other tests reaching this symbol 1
Relations§
Instantiated in 1
Type checks 3
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Resolution\FromScope::open() packages/sql-semantics-postgres/src/Rules/Resolution/FromScope.php:61
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Resolution\FromScope::visible() packages/sql-semantics-postgres/src/Rules/Resolution/FromScope.php:75
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Resolution\LateralReach::report() packages/sql-semantics-postgres/src/Rules/Resolution/LateralReach.php:110