classInSubquery
final class InSubquery
implements Scalar
uses Snapshot
@visibility public.A membership test against the rows of a query: a [NOT] IN (SELECT …).
Mirrors PostgreSQL's SubLink node of kind ANY_SUBLINK with the operator =; NOT IN is the negation of that test.
Rule: PG-IN-SUBQUERY-001. The query is derived in the environment of the expression; it returns one column, or as many as the fields of a row constructor on the left. Facts: the type of = over the value and the column (PG-OPERATOR-TYPING-001); NULL when no row matches and a compared value is NULL, so the result can be NULL. The value must keep its place before IN (PG-PRECEDENCE-001). Source: https://www.postgresql.org/docs/17/functions-subquery.html#FUNCTIONS-SUBQUERY-IN. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 NOT IN (SELECT 2)');
[$query->field(0)->expression->negated, $query->field(0)->type->descriptor->name()] // => [true, 'boolean']Properties§
public Scalar $operandpublic bool $negatedpublic Query $queryMethods§
public function __construct(public Scalar $operand, public bool $negated, public Query $query)Parameters
$operand | Scalar | The tested value |
$negated | bool | Whether NOT is written |
$query | Query | The query inside the parentheses |
Calls 4
- static-call Check::input() line 49
- method-call Precedence::before() line 49
- new Precedence line 49
- class-const Precedence::PATTERN() line 49
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the value and the query, and the comparison of the value with its rows.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- method-call Derivation::scalar() line 57
- method-call Derivation::query() line 58
- new ScalarFact line 60
- method-call Sublinks::compared() line 60
- new Sublinks line 60
- class-const Nullability::Nullable() line 60
public function render(Output $out): voidWrites the value, [NOT] IN and the query in parentheses.
Parameters
$out | Output |
Test cases 1
Calls 2
- method-call Output::node() line 68
- method-call Output::keyword() line 70
Test cases 3§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.