Like operator
The Like operator enables advanced pattern matching.
It works basically the same as its precedetor from SQL.
The most common use case is to validate a file name.
select files
  where name like '%abc_'
This operator is case sensitive. Insensitivity is possible, but requires an additional conversion to lowercase.
select files
  where lower(name) like '%abc_'
Below is the list of all wildcard characters and their meaning.
symbol | meaning |
_ |
one character |
# |
one digit |
% |
nothing, one or multiple characters |
[] |
one character from a set within brackets |
[-] |
one character from a range (works as expected with digits and English letters) |
[^] |
any character not in the brackets, used like: [^a-c] |
Brackets can contain multiple sets and ranges. For example,
[a-zA-Z123] means all English letters and digits
1,
2 and
3.
Caret character negates entire brackets' content. It works as a wildcard, but only if appears right after
[.
Outside of brackets, caret and minus are not wildcards. Similarly, within brackets, characters
_,
# and
% represent themselves.
If the pattern is not valid and for example not all of its opened brackets are closed, then it will never match any pattern at all.
name like '%ab[_]'
name like '%ab[#]'
name like '%ab[%]'
name like '%ab[[]'
name like '%ab]'
If you want to treat certain wildcard character as a normal character, embrace it by square brackets. All possible hacks are shown above.
Character
] does not even require this effort and can be put directly.
Language Perun2 contains its own custom operator that in many cases is more useful than the Like operator.
Go here to read about the Resembles operator.