final class QueryExpression
    implements Statement, Query, OutputNaming
    uses Snapshot
Public API: explicitly declared with @visibility public.

A query body with a WITH clause before it, or ORDER BY, LIMIT and locking clauses after it.

Mirrors select_no_parens with clauses around a select_clause. PostgreSQL attaches the clauses to the query inside any parentheses, so ORDER BY after a parenthesized selection still sees its FROM items. A selection and a TABLE query hold the clauses written directly after them themselves; this node then holds only the WITH clause. The facts follow PG-QUERY-EXPRESSION-001. Source: https://www.postgresql.org/docs/17/sql-select.html. Status: Implemented.

Reading ORDER BY after a set operationdoctest
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 AS a UNION SELECT 2 ORDER BY a');
    [$query->statement->body instanceof \SqlSemantics\Platform\PostgreSql\Statement\Query\SetOperation, count($query->statement->options->order)] // => [true, 1]
Refusing clauses that belong to a selectiondoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Query\QueryExpression(null, new \SqlSemantics\Platform\PostgreSql\Statement\Query\Select([]), new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\SelectOptions(readOnly: true)) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public WithClause|null $with
public Query $body
public SelectOptions|null $options = null

Methods§

public function __construct(
    public WithClause|null $with,
    public Query $body,
    public SelectOptions|null $options = null,
)

Parameters

$withWithClause|nullThe WITH clause
$bodyQueryThe query body
$optionsSelectOptions|nullThe ORDER BY, LIMIT and locking clauses written after the body
Calls 1
public function outputName(): ?Name

Answers the name of the first output column of the body.

Returns

Calls 1
public function deriveStatement(Derivation $derivation): void

Derives the query as a statement root.

Parameters

$derivationDerivation
Calls 2
public function deriveQuery(Derivation $derivation, Environment $outer): QueryFact

Derives the WITH clause, the body and the clauses after it.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the WITH clause, the body and the clauses after it.

Parameters

$outOutput
Calls 1

Test cases 16§

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 15

Relations§

Instantiated in 1
Type checks 11
Type declarations 4