classScalarSubquery
final class ScalarSubquery
implements Scalar, OutputNaming
uses Snapshot
@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.
(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT (SELECT 1)')->field(0)->nullability // => \SqlSemantics\Platform\PostgreSql\Model\Statement\Type\Nullability::NullableProperties§
public Query $queryMethods§
public function __construct(public Query $query)Parameters
$query | Query | The query inside the parentheses |
public function outputName(): ?NameNames an unaliased result column as the query names its first column.
Returns
?NameTest cases 1
Calls 1
- method-call Query::outputName() line 54
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the query and the value it yields.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 5
- method-call Derivation::query() line 62
- new ScalarFact line 64
- method-call Sublinks::value() line 64
- new Sublinks line 64
- class-const Nullability::Nullable() line 64
public function render(Output $out): voidWrites the query in parentheses.
Parameters
$out | Output |
Test cases 1
Calls 1
- method-call Output::symbol() line 72
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
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\PrimaryRule::lower() packages/sql-semantics-postgres/src/Lowering/Expression/PrimaryRule.php:69
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\PrimaryRule::lower() packages/sql-semantics-postgres/src/Lowering/Expression/PrimaryRule.php:70
Type checks 8
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::row() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:184
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::row() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:193
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::types() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:224
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Manipulation\Assignments::types() packages/sql-semantics-postgres/src/Rules/Manipulation/Assignments.php:225
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Expression\Grouped::__construct() packages/sql-semantics-postgres/src/Statement/Expression/Grouped.php:45
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Expression\Indirection::__construct() packages/sql-semantics-postgres/src/Statement/Expression/Indirection.php:63
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Expression\Subquery\InList::__construct() packages/sql-semantics-postgres/src/Statement/Expression/Subquery/InList.php:53
- instanceof SqlSemantics\Platform\PostgreSql\Statement\Expression\Subquery\QuantifiedArray::__construct() packages/sql-semantics-postgres/src/Statement/Expression/Subquery/QuantifiedArray.php:50