Make sure `LIKE` patterns intersect in Postgres

In one query, there are two lines that are patterns that are used in expressions LIKE(with _and %placeholders). I want to find if these patterns intersect (there is a line that matches both of them). Is there any way to do this? ...


A "similar pattern" corresponds to a finite or infinite set of lines. Each row in this set corresponds to a given pattern. I want to check if the intersection of row sets is not for two given patterns. Thus, it is better to say a combination of patterns. In math language:

S - a set of strings
P - a set of patterns (where each pattern has one or more string representations)

Sᵢ is the subset of rows (Sᵢ ⊂ S) that correspond to the pattern pᵢ (where instead of i it can be any index). In the form of the equation: "Sᵢ = {s | s ∈ S, s corresponds to pᵢ, pᵢ ∈ P}" is meas: "Sᵢ is a set of elements that are strings and correspond to a pᵢ-pattern." Or another notation: "Sᵢ ⊂ S, ∀pᵢ ∈ P ∀s ∈ S (s corresponds to pᵢ ≡ s ∈ Sᵢ)" is meas: "Sᵢ is a subset of rows, and any row is an element from Sᵢ if it corresponds to pᵢ -sample ".

Define a join of patterns: "p₁ ∧ p₂ = p₃ ≡ S₁ ∩ ​​S₂ = S₃" - this means: "A set of lines that correspond to a combination of patterns p₁ and p₂ is the intersection of sets of lines that correspond to a pattern of p₁, and that match p₂ pattern ".


For instance:

  • ab_dand %cd- intersects
  • k%nand kl___- crosses
+5
1

, ( , ). ?... (...) , .

, , : p1 p2, , ( ) , p1, p2.

:.

select check_pattern('a%', 'b_'); -- false
select check_pattern('a%', '_b'); -- true ('ab')

, ?

, SQL imho, " () , / , ". SQL, , , , , , .

, , C, Perl, Lisp, .

:

  • p1 p2 , : %foo% %bar%, , , foo%, %bar.

  • p1 (.. %), p1 generate_series() for/while/whatever p2 . , .

  • p1 p2 (, abc% def% %abc %def), (, _abc% abcd%), , .

  • , , ...

, , , , , , () , .

+1

All Articles