classUnaryOperation
final class UnaryOperation
implements Scalar
uses Snapshot
@visibility public.A prefix operator applied to one operand: - a, + a, @ a, OPERATOR(s.!!) a.
Mirrors PostgreSQL's A_Expr node of kind AEXPR_OP without a left operand. The parser folds a minus before a numeric constant into a negative constant; the model keeps the operator and types the pair as that constant.
Rule: PG-UNARY-OPERATION-001. Facts follow PG-OPERATOR-TYPING-001. Only +, -, an operator the scanner reads as a general operator, or the OPERATOR(...) syntax can be written before an operand. The operand must keep its 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-SYNTAX-OPERATORS. Status: Implemented.
(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT -2147483648')->field(0)->type->descriptor->name() // => 'integer'new \SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\UnaryOperation(new \SqlSemantics\Platform\PostgreSql\Statement\Name\OperatorName(new \SqlSemantics\Platform\PostgreSql\Model\Statement\Identifier\Name('*')), new \SqlSemantics\Platform\PostgreSql\Statement\Literal\NullLiteral()) // throws \SqlSemantics\Platform\PostgreSql\Model\Diagnostic\InvalidConstructionProperties§
public OperatorName $operatorpublic Scalar $operandMethods§
public function __construct(public OperatorName $operator, public Scalar $operand)Parameters
$operator | OperatorName | The operator |
$operand | Scalar | The operand |
Calls 6
- static-call Check::input() line 53
- function-call
in_arrayline 54 - class-const UnaryOperation::SELF() line 54
- new Precedence line 55
- method-call Precedence::after() line 56
- method-call Precedence::operator() line 56
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operand and the result of the operator over its type.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 3
- method-call Derivation::scalar() line 64
- method-call PrefixTyping::prefix() line 66
- new PrefixTyping line 66
public function render(Output $out): voidWrites the operator and the operand.
Parameters
$out | Output |
Test cases 1
Calls 1
- method-call Output::node() line 74
Private surface 1§
Implementation details, listed for orientation only.
private const SELF = ['*', '/', '%', '^', '<', '>', '=', '<=', '>=', '<>']Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 5
UnaryOperationTest::testDeriveScalarKeepsTheTypeOfANegatedNumbercallsUnaryOperationTest::testDeriveScalarTypesANegativeConstantByItsValuecallsUnaryOperationTest::testRejectsAnOperandThatBindsWeakercallsUnaryOperationTest::testRejectsAnOperatorThatCannotBePrefixcallsUnaryOperationTest::testRenderWritesTheOperatorFirstcalls
Other tests reaching this symbol 4
Relations§
Instantiated in 3
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\Expressions::negation() packages/sql-semantics-postgres/src/Lowering/Expression/Expressions.php:132
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\OperatorRule::operators() packages/sql-semantics-postgres/src/Lowering/Expression/OperatorRule.php:85
- new SqlSemantics\Platform\PostgreSql\Lowering\Expression\OperatorRule::operators() packages/sql-semantics-postgres/src/Lowering/Expression/OperatorRule.php:86
Type checks 6
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Expression\Precedence::operators() packages/sql-semantics-postgres/src/Rules/Expression/Precedence.php:205
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Expression\Precedence::restricted() packages/sql-semantics-postgres/src/Rules/Expression/Precedence.php:284
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\FetchCounts::admits() packages/sql-semantics-postgres/src/Rules/Query/FetchCounts.php:36
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Positions::value() packages/sql-semantics-postgres/src/Rules/Query/Positions.php:39
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Positions::value() packages/sql-semantics-postgres/src/Rules/Query/Positions.php:40
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Query\Positions::misused() packages/sql-semantics-postgres/src/Rules/Query/Positions.php:56