classBinaryOperation
final class BinaryOperation
implements Scalar, OutputNaming
uses Snapshot
@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.
$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'](new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT 1 + 2.5')->field(0)->type->descriptor->name() // => 'numeric'$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\InvalidConstructionProperties§
public OperatorName $operatorpublic Scalar $leftpublic Scalar $rightMethods§
public function __construct(
public OperatorName $operator,
public Scalar $left,
public Scalar $right,
)Parameters
$operator | OperatorName | The operator |
$left | Scalar | The left operand |
$right | Scalar | The right operand |
Calls 5
- static-call Check::input() line 59
- new Precedence line 60
- method-call Precedence::operator() line 61
- method-call Precedence::before() line 62
- method-call Precedence::after() line 63
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operands and the result of the operator over their types.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 3
- method-call Derivation::scalar() line 79
- method-call OperatorTyping::binary() line 82
- new OperatorTyping line 82
public function render(Output $out): voidWrites the left operand, the operator and the right operand.
Parameters
$out | Output |
Test cases 1
Calls 1
- method-call Output::node() line 90
Test cases 33§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 10
BinaryOperationTest::testAcceptsAGroupedOperandcallsBinaryOperationTest::testDeriveScalarDependsOnAnOperatorOutsideTheCatalogcallsBinaryOperationTest::testDeriveScalarIsBooleanForCatalogComparisonscallsBinaryOperationTest::testDeriveScalarIsNullableWhenAnOperandIsNullcallsBinaryOperationTest::testDeriveScalarPromotesAnIntegerAndANumericcallsBinaryOperationTest::testOutputNameIsNonecallsBinaryOperationTest::testRejectsALeftOperandThatBindsWeakercallsBinaryOperationTest::testRejectsAQualifiedOperatorWithoutTheOperatorSyntaxcallsBinaryOperationTest::testRejectsARightOperandOfTheSameLevelcallsBinaryOperationTest::testRenderWritesTheOperatorBetweenTheOperandscalls
Other tests reaching this symbol 23
ExpressionsTest::testExpressionLowersOperatorsByPrecedencecallsPrecedenceTest::testAfterTellsWhetherAnOperandKeepsItsPlaceAfterATokencallsPrecedenceTest::testBeforeTellsWhetherAnOperandKeepsItsPlaceBeforeATokencallsPrecedenceTest::testClosingIsTheWeakestRuleOnTheRightEdgecallsPrecedenceTest::testOpeningIsTheWeakestTokenOnTheLeftEdgecallsPrecedenceTest::testRestrictedTellsBExprFormscallsCommonTableFactsTest::testShapeAddsTheSearchAndCycleColumnscallsSetOperationFactsTest::testReboundBindsTheRecursiveTablecallsFetchCountsTest::testAdmitsAPrimaryExpressionOrASignedConstantcallsColumnCheckTest::testDeriveClauseResolvesTheConditionAgainstTheTablecallsCastTest::testRejectsAnOperandThatBindsWeakercallsAtLocalTest::testRejectsAProductAsTheValuecallsAtTimeZoneTest::testRejectsASumAsTheZonecallsBetweenTest::testRejectsATestedComparisoncallsNegationTest::testDeriveScalarIsBooleancallsUnaryOperationTest::testDeriveScalarKeepsTheTypeOfANegatedNumbercallsUnaryOperationTest::testRejectsAnOperandThatBindsWeakercallsNullTestTest::testAcceptsAComparisoncallsQuantifiedSubqueryTest::testRejectsASumBeforeAProductOperatorcallsJsonPairTest::testRejectsAKeyBeforeValueThatIsNotPrimarycallsXmlExistsTest::testRejectsAPathThatIsNotPrimarycallsXmlPassingTest::testRejectsADocumentThatIsNotPrimarycallsCreateFunctionTest::testDeriveStatementResolvesParametersInTheBodycalls
Relations§
Instantiated in 2
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\Expressions::comparison() packages/sql-semantics-postgres/src/Lowering/Expression/Expressions.php:113
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\OperatorRule::operators() packages/sql-semantics-postgres/src/Lowering/Expression/OperatorRule.php:80
Type checks 2
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Expression\Precedence::operators() packages/sql-semantics-postgres/src/Rules/Expression/Precedence.php:200
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Expression\Precedence::restricted() packages/sql-semantics-postgres/src/Rules/Expression/Precedence.php:284