final class ScalarSubquery
    implements Scalar, OutputNaming
    uses Snapshot
Public API: explicitly declared with @visibility public.

A query in parentheses used as a value: (SELECT …), the value of its one row, or NULL when it returns none.

Mirrors PostgreSQL's SubLink node of kind EXPR_SUBLINK; compared with a row constructor it is a row comparison (ROWCOMPARE_SUBLINK).

Rule: PG-SCALAR-SUBQUERY-001. The query is derived in the environment of the expression, so it can refer to the enclosing queries. Facts: a query of one column yields that column's type; a query of several columns yields a row of them, which only a row comparison accepts; a query of an open shape depends on its missing inputs; a query of no column is reported. The value can always be NULL. An unaliased result column is named as the query names its first column. Source: https://www.postgresql.org/docs/17/sql-expressions.html#SQL-SYNTAX-SCALAR-SUBQUERIES. Status: Implemented.

A scalar subquery can be NULLdoctest
(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT (SELECT 1)')->field(0)->nullability // => \SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability::Nullable

Properties§

public Query $query

Methods§

public function __construct(public Query $query)

Parameters

$queryQueryThe query inside the parentheses
public function outputName(): ?Name

Names an unaliased result column as the query names its first column.

Returns

Test cases 1
Calls 1
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the query and the value it yields.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes the query in parentheses.

Parameters

$outOutput
Test cases 1
Calls 1

Test cases 7§

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

Dedicated tests 4
Other tests reaching this symbol 3

Relations§

Instantiated in 2
Type checks 8
Type declarations 1