classOperatorTyping
final class OperatorTyping
Types operator applications over catalog types.
Rule: PG-OPERATOR-TYPING-001. An operator is looked up by name and operand types along the search path; a context declares no operators, so a result is known only when pg_catalog is searched before any other schema (or the operator is qualified with it) and the operand types select one of the catalog operators below; every other combination depends on the operator's declaration. An invalid operand makes the result invalid, a dependent operand makes it depend on the same inputs. An operand of the pseudo-type unknown (a string constant or NULL) takes the type of the other operand. The table: the six comparisons are boolean for operands of one category among numbers, strings, date and timestamp types, and for the self-comparable types of PG-OPERATOR-COMPARISON-001, rows and arrays; + - * / over numbers give the wider of two integer types, numeric with an integer and numeric, double precision once a floating-point type and another type meet, and the type itself for two equal types; % is defined for integers and numeric; ^ for double precision and numeric, integers reaching it as double precision; date/time arithmetic follows the table of functions-datetime.html; || gives text when a side is a string, the array type for arrays, and the type itself for bytea, bit strings, jsonb, tsvector and tsquery; the bitwise operators keep the integer or bit-string type; the JSON operators follow functions-json.html; prefix - and + keep a number or interval type, and - before a numeric constant is that negative constant, typed by its value. Comparisons and arithmetic are strict: the result can be NULL when an operand can. Termination: constant work. Source: https://www.postgresql.org/docs/17/typeconv-oper.html, https://www.postgresql.org/docs/17/functions-comparison.html, https://www.postgresql.org/docs/17/functions-math.html, https://www.postgresql.org/docs/17/functions-datetime.html, https://www.postgresql.org/docs/17/functions-string.html, https://www.postgresql.org/docs/17/functions-json.html, https://www.postgresql.org/docs/17/functions-array.html, https://www.postgresql.org/docs/17/functions-bitstring.html. Status: Implemented.
Methods§
public function binary(
AnalysisContext $context,
OperatorName $operator,
ScalarFact $left,
ScalarFact $right,
): ScalarFactTypes a binary operator application and derives that it can be NULL when an operand can.
Parameters
$context | AnalysisContext | |
$operator | OperatorName | |
$left | ScalarFact | |
$right | ScalarFact |
Returns
Test cases 1
Called from 1
Calls 4
- new ScalarFact line 102
- method-call OperatorTyping::named() line 102
- method-call OperandChecks::nullability() line 102
- new OperandChecks line 102
public function named(
AnalysisContext $context,
OperatorName|string $operator,
TypeFact $left,
TypeFact $right,
): TypeFactTypes an application of a binary operator given by name or as an operator name.
Parameters
$context | AnalysisContext | |
$operator | OperatorName|string | |
$left | TypeFact | |
$right | TypeFact |
Returns
Test cases 1
Called from 11
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\CaseTyping::derive() packages/sql-semantics-postgres/src/Rules/Expression/Typing/CaseTyping.php:46
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\OperatorTyping::binary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/OperatorTyping.php:102
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::pattern() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:54
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::compared() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:93
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::compared() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:100
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::elements() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:116
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::elements() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:119
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\Between::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/Between.php:72
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\DistinctTest::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/DistinctTest.php:58
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Subquery\InList::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Subquery/InList.php:68
- method-call SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\NullIf::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/NullIf.php:64
Calls 8
- function-call
is_stringline 110 - new OperatorName line 110
- new Name line 110
- method-call OperatorTyping::visible() line 116
- method-call OperatorTyping::undeclared() line 117
- method-call OperatorTyping::structured() line 119
- method-call OperatorTyping::catalog() line 119
- new Known line 121
public function structured(
string $operator,
TypeFact $left,
TypeFact $right,
): Builtin|ArrayOf|nullTypes an operator over rows and arrays.
Test cases 1
Called from 1
Calls 4
- function-call
in_arrayline 134 - class-const OperatorTyping::COMPARISONS() line 134
- class-const Builtin::Bool() line 134
- method-call OperatorTyping::arrays() line 137
public function arrays(
string $operator,
TypeDescriptor $left,
TypeDescriptor $right,
): Builtin|ArrayOf|nullTypes an operator over arrays: comparison and containment of equal array types, and || with arrays or elements.
Parameters
$operator | string | |
$left | TypeDescriptor | |
$right | TypeDescriptor |
Test cases 1
Called from 1
Calls 4
- method-call TypeDescriptor::name() line 145
- function-call
in_arrayline 146 - class-const OperatorTyping::COMPARISONS() line 146
- class-const Builtin::Bool() line 147
Types an operator over catalog base types; null when no catalog operator applies.
Returns
Test cases 1
Called from 1
Calls 14
- new Categories line 167
- method-call Categories::builtin() line 168
- class-const Builtin::Unknown() line 173
- function-call
in_arrayline 174 - class-const OperatorTyping::COMPARISONS() line 174
- class-const Builtin::Bool() line 174
- class-const Builtin::Text() line 174
- method-call OperatorTyping::comparable() line 182
- class-const OperatorTyping::EXACT() line 184
- static-call Builtin::from() line 186
- new Arithmetic line 189
- method-call Arithmetic::arithmetic() line 191
- method-call Arithmetic::concatenation() line 191
- method-call Arithmetic::bitwise() line 191
Tells whether pg_catalog compares two types, directly or after implicit conversion within their category.
Returns
boolTest cases 1
Called from 1
Calls 10
- new Categories line 199
- method-call ComparisonTyping::exact() line 200
- new ComparisonTyping line 200
- method-call Categories::numeric() line 203
- method-call Categories::textual() line 203
- class-const Builtin::Date() line 206
- class-const Builtin::Timestamp() line 206
- class-const Builtin::Timestamptz() line 206
- function-call
in_arrayline 208 - method-call Categories::category() line 209
Combines the types of two boolean conditions that make one test.
Returns
Test cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::compared() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:100
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\Between::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/Between.php:72
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Subquery\InList::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Subquery/InList.php:72
Calls 5
- new Dependent line 223
- method-call Unification::distinct() line 223
- new Unification line 223
- new Known line 229
- class-const Builtin::Bool() line 229
public function visible(
AnalysisContext $context,
string $name,
?OperatorName $operator = null,
): boolTells whether a routine or operator name resolves in pg_catalog before any other schema.
Parameters
$context | AnalysisContext | |
$name | string | |
$operator | ?OperatorName |
Returns
boolTest cases 1
Called from 3
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\OperatorTyping::named() packages/sql-semantics-postgres/src/Rules/Expression/Typing/OperatorTyping.php:116
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::zone() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:78
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:84
Calls 1
- function-call
countline 238
public function undeclared(string $name): DependentAnswers the fact of an operator or routine that only a declaration can type.
Parameters
$name | string |
Returns
Test cases 2
Called from 5
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\OperatorTyping::named() packages/sql-semantics-postgres/src/Rules/Expression/Typing/OperatorTyping.php:117
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\OperatorTyping::named() packages/sql-semantics-postgres/src/Rules/Expression/Typing/OperatorTyping.php:121
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::zone() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:78
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:85
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:96
Calls 4
- new Dependent line 254
- new UndeclaredRoutine line 254
- new QualifiedName line 254
- new Name line 254
Private surface 2§
Implementation details, listed for orientation only.
private const EXACT = ['+ date int4' => 'date', '+ int4 date' => 'date', '- date int4' => 'date', '- …private const COMPARISONS = ['=', '<>', '<', '>', '<=', '>=']Test cases 9§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
OperatorTypingTest::testArraysTypesContainmentcallsOperatorTypingTest::testBinaryTypesAndPropagatesNullcallsOperatorTypingTest::testBothIsBooleanUnlessAConditionDependscallsOperatorTypingTest::testCatalogTypesDateTimeArithmeticcallsOperatorTypingTest::testComparableAcceptsMixedNumberscallsOperatorTypingTest::testNamedDependsOnAnOperatorOutsideThePathcallsOperatorTypingTest::testStructuredTypesArrayConcatenationcallsOperatorTypingTest::testUndeclaredNamesTheRoutinecallsOperatorTypingTest::testVisibleNeedsTheCatalogFirstcalls
Relations§
Instantiated in 13
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\CaseTyping::derive() packages/sql-semantics-postgres/src/Rules/Expression/Typing/CaseTyping.php:46
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::pattern() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:54
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::zone() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:78
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:84
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:85
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:96
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::compared() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:90
- new SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::elements() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:111
- new SqlSemantics\Platform\PostgreSql\Statement\Expression\BinaryOperation::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/BinaryOperation.php:82
- new SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\Between::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/Between.php:69
- new SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\DistinctTest::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/DistinctTest.php:58
- new SqlSemantics\Platform\PostgreSql\Statement\Expression\Subquery\InList::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Subquery/InList.php:63
- new SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\NullIf::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/NullIf.php:64
Method calls 19
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\CaseTyping::derive() packages/sql-semantics-postgres/src/Rules/Expression/Typing/CaseTyping.php:46
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::pattern() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:54
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::zone() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:78
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PredicateTyping::zone() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PredicateTyping.php:78
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:84
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:85
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\PrefixTyping::unary() packages/sql-semantics-postgres/src/Rules/Expression/Typing/PrefixTyping.php:96
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::compared() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:93
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::compared() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:100
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::compared() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:100
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::elements() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:116
- method-call SqlSemantics\Platform\PostgreSql\Rules\Expression\Typing\Sublinks::elements() packages/sql-semantics-postgres/src/Rules/Expression/Typing/Sublinks.php:119
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\BinaryOperation::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/BinaryOperation.php:82
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\Between::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/Between.php:72
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\Between::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/Between.php:72
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Operator\DistinctTest::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Operator/DistinctTest.php:58
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Subquery\InList::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Subquery/InList.php:68
- method-call SqlSemantics\Platform\PostgreSql\Statement\Expression\Subquery\InList::deriveScalar() packages/sql-semantics-postgres/src/Statement/Expression/Subquery/InList.php:72
- method-call SqlSemantics\Platform\PostgreSql\Statement\Invocation\Conditional\NullIf::deriveScalar() packages/sql-semantics-postgres/src/Statement/Invocation/Conditional/NullIf.php:64