final class UnaryOperation
    implements Scalar
    uses Snapshot
Public API: explicitly declared with @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.

Typing a negated constant as the constant it folds todoctest
(new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze('SELECT -2147483648')->field(0)->type->descriptor->name() // => 'integer'
Rejecting an operator that cannot be written before an operanddoctest
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\InvalidConstruction

Properties§

public OperatorName $operator
public Scalar $operand

Methods§

public function __construct(public OperatorName $operator, public Scalar $operand)

Parameters

$operatorOperatorNameThe operator
$operandScalarThe operand
Calls 6
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFact

Derives the operand and the result of the operator over its type.

Parameters

$derivationDerivation
$environmentEnvironment

Returns

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

Writes the operator and the operand.

Parameters

$outOutput
Test cases 1
Calls 1

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
Other tests reaching this symbol 4

Relations§

Instantiated in 3
Type checks 6
Type declarations 1