classPatternMatch
final class PatternMatch
implements Scalar
uses Snapshot
@visibility public.A pattern match: a [NOT] LIKE p, ILIKE, SIMILAR TO, with an optional ESCAPE e.
Mirrors PostgreSQL's A_Expr node of kind AEXPR_LIKE, AEXPR_ILIKE or AEXPR_SIMILAR; an ESCAPE clause becomes a call of like_escape or similar_to_escape on the pattern.
Rule: PG-PATTERN-MATCH-001. Facts: the type of the matching operator over the operands (PG-OPERATOR-TYPING-001): boolean for string operands, and for bytea with LIKE; NULL when an operand can be. The value must keep its place before the keyword, the pattern after it, and the escape after ESCAPE; with ESCAPE, the pattern may not end in a match without one, which would take it (PG-PRECEDENCE-001). Source: https://www.postgresql.org/docs/17/functions-matching.html. Status: Implemented.
$query = (new \SqlSemantics\Platform\PostgreSql\Semantics())->analyze("SELECT 'a' NOT LIKE 'a!%' ESCAPE '!'");
[$query->field(0)->expression->escape->value->value, $query->field(0)->type->descriptor->name()] // => ['!', 'boolean']Properties§
public Scalar $leftpublic PatternOperator $operatorpublic bool $negatedpublic Scalar $rightpublic Scalar|null $escape = nullMethods§
public function __construct(
public Scalar $left,
public PatternOperator $operator,
public bool $negated,
public Scalar $right,
public Scalar|null $escape = null,
)Parameters
$left | Scalar | The matched value |
$operator | PatternOperator | The matching keyword |
$negated | bool | Whether NOT is written |
$right | Scalar | The pattern |
$escape | Scalar|null | The escape character, or null when ESCAPE is not written |
Calls 6
- new Precedence line 56
- static-call Check::input() line 57
- method-call Precedence::before() line 57
- class-const Precedence::PATTERN() line 57
- method-call Precedence::after() line 58
- method-call Precedence::takesEscape() line 59
public function deriveScalar(Derivation $derivation, Environment $environment): ScalarFactDerives the operands and the type of the match.
Parameters
$derivation | Derivation | |
$environment | Environment |
Returns
Calls 6
- method-call Derivation::scalar() line 67
- new ScalarFact line 72
- method-call PredicateTyping::pattern() line 72
- new PredicateTyping line 72
- method-call OperandChecks::nullability() line 72
- new OperandChecks line 72
public function render(Output $out): voidWrites the value, the keyword, the pattern and the escape.
Parameters
$out | Output |
Test cases 1
Calls 5
- method-call Output::node() line 80
- method-call Output::keyword() line 82
- class-const PatternOperator::Like() line 85
- class-const PatternOperator::ILike() line 86
- class-const PatternOperator::SimilarTo() line 87
Test cases 8§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 4
Other tests reaching this symbol 4
Relations§
Instantiated in 1
Type checks 2
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Expression\Precedence::operators() packages/sql-semantics-postgres/src/Rules/Expression/Precedence.php:234
- instanceof SqlSemantics\Platform\PostgreSql\Rules\Expression\Precedence::takesEscape() packages/sql-semantics-postgres/src/Rules/Expression/Precedence.php:345