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

A selection: the SELECT form of PostgreSQL's SelectStmt without set operation.

Rule: PG-SELECT-001. Holds, in grammar order, DISTINCT [ON], the select list, INTO, FROM (one item, or a comma list of several), WHERE, GROUP BY with its quantifier, HAVING, WINDOW, and the ORDER BY, LIMIT and locking clauses written directly after it. The facts follow PG-SELECT-SCOPE-001. An integer constant in GROUP BY must be given as an output position. DISTINCT requires a select list. Source: https://www.postgresql.org/docs/17/sql-select.html. Status: Implemented.

Reading the parts of a selectiondoctest
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT DISTINCT a, 1 FROM t WHERE a > 1 GROUP BY a HAVING a > 2 ORDER BY a LIMIT 3');
    [count($query->statement->targets), $query->statement->distinct !== null, count($query->statement->groupBy), count($query->statement->options->order), $query->toString()] // => [2, true, 1, 1, 'SELECT DISTINCT a, 1 FROM t WHERE a > 1 GROUP BY a HAVING a > 2 ORDER BY a LIMIT 3']
Refusing DISTINCT without a select listdoctest
new \SqlSemantics\Platform\PostgreSql\Statement\Query\Select([], distinct: new \SqlSemantics\Platform\PostgreSql\Statement\Query\Clause\DistinctClause()) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public list<Target> $targets
public list<Scalar|GroupingRow|GroupingSet> $groupBy
public list<WindowDefinition> $windows
public Relation|null $from = null
public Scalar|null $where = null
public Scalar|null $having = null
public DistinctClause|null $distinct = null
public IntoClause|null $into = null
public SetQuantifier|null $groupQuantifier = null
public SelectOptions|null $options = null

Methods§

public function __construct(
    list<Target> $targets,
    public Relation|null $from = null,
    public Scalar|null $where = null,
    list<Scalar|GroupingRow|GroupingSet> $groupBy = [],
    public Scalar|null $having = null,
    list<WindowDefinition> $windows = [],
    public DistinctClause|null $distinct = null,
    public IntoClause|null $into = null,
    public SetQuantifier|null $groupQuantifier = null,
    public SelectOptions|null $options = null,
)

Parameters

$targetslist<Target>The select-list items in output order
$fromRelation|nullThe FROM item, or the list of FROM items
$whereScalar|nullThe row predicate
$groupBylist<Scalar|GroupingRow|GroupingSet>The GROUP BY items
$havingScalar|nullThe group predicate
$windowslist<WindowDefinition>The named windows
$distinctDistinctClause|nullThe DISTINCT clause
$intoIntoClause|nullThe table SELECT INTO creates
$groupQuantifierSetQuantifier|nullThe ALL or DISTINCT written after GROUP BY
$optionsSelectOptions|nullThe ORDER BY, LIMIT and locking clauses written after the selection
Calls 11
public function input(): ?Relation

Answers the input relation.

Returns

public function outputName(): ?Name

Answers the name of the first output column, when the select list fixes it.

Returns

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

Derives the selection as a statement root.

Parameters

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

Derives the input, every clause and the output fields.

Parameters

$derivationDerivation
$outerEnvironment

Returns

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

Writes the clauses in grammar order.

Parameters

$outOutput
Calls 3

Test cases 53§

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

Dedicated tests 2
Other tests reaching this symbol 51

Relations§

Instantiated in 1
Type checks 11
Type declarations 7