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

An operator applied to a left and a right operand: a + b, a = b, a OPERATOR(s.@@) b.

Mirrors PostgreSQL's A_Expr node of kind AEXPR_OP with two operands: the operator is a name looked up by the operand types, not a member of a closed set.

Rule: PG-BINARY-OPERATION-001. Facts follow PG-OPERATOR-TYPING-001; the catalog operators are strict, so the result can be NULL exactly when an operand can. In an expression a qualified operator is written with the OPERATOR(...) syntax. Both operands must keep their place without parentheses (PG-PRECEDENCE-001). Source: https://www.postgresql.org/docs/17/sql-expressions.html#SQL-EXPRESSIONS-OPERATOR-CALLS, https://www.postgresql.org/docs/17/sql-syntax-lexical.html#SQL-PRECEDENCE, https://www.postgresql.org/docs/17/typeconv-oper.html. Status: Implemented.

Reading a comparisondoctest
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT a FROM t WHERE a >= 1');
    [$query->statement->where->operator->name->value, $query->statement->where->right->value->digits] // => ['>=', '1']
Reading the type of an arithmetic operationdoctest
(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 + 2.5')->field(0)->type->descriptor->name() // => 'numeric'
Rejecting an operand that would need parenthesesdoctest
$one = new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('1'));
    $two = new \SqlSemantics\Platform\PostgreSql\Statement\Literal\Constant(new \SqlSemantics\Platform\PostgreSql\Statement\Literal\IntegerConstant('2'));
    $plus = new \SqlSemantics\Platform\PostgreSql\Statement\Name\OperatorName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('+'));
    $times = new \SqlSemantics\Platform\PostgreSql\Statement\Name\OperatorName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('*'));
    new \SqlSemantics\Platform\PostgreSql\Statement\Expression\BinaryOperation($times, new \SqlSemantics\Platform\PostgreSql\Statement\Expression\BinaryOperation($plus, $one, $two), new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral()) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstruction

Properties§

public OperatorName $operator
public Scalar $left
public Scalar $right

Methods§

public function __construct(
    public OperatorName $operator,
    public Scalar $left,
    public Scalar $right,
)

Parameters

$operatorOperatorNameThe operator
$leftScalarThe left operand
$rightScalarThe right operand
Calls 5
public function outputName(): ?Name

Gives a result column no name.

Returns

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

Derives the operands and the result of the operator over their types.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes the left operand, the operator and the right operand.

Parameters

$outOutput
Test cases 1
Calls 1

Test cases 33§

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

Dedicated tests 10
Other tests reaching this symbol 23

Relations§

Instantiated in 2
Type checks 2
Type declarations 1