postgresql / sqlite / mysql /oracle regular expression operators
See original GitHub issueMigrated issue, originally created by Anonymous
match operator not implemented
in sqlalchemy/databases/postgres.py 727 just add sql_operators.match_op: lambda x, y, escape=None: ‘%s ~ %s’ % (x, y) + (escape and ’ ESCAPE '%s'’ % escape or ‘’),
and it works for me CAVEAT sql might crash if improper regexp syntax entered.
- missing imatch / notmatch …
(these matching functions are still used with same syntax) http://www.postgresql.org/docs/7.4/interactive/functions-matching.html
Attachments: 1390.patch
Edit 2020-07-10
Coping this recap from https://github.com/sqlalchemy/sqlalchemy/issues/5447#issue-654578670
The call column.regex_match('[a-z]*')
would then evaluate to:
Issue Analytics
- State:
- Created 14 years ago
- Comments:59 (29 by maintainers)
Top Results From Across the Web
MYSQL Regular Expressions (REGEXP) with Syntax ... - Guru99
“REGEXP 'pattern'” REGEXP is the regular expression operator and 'pattern' represents the pattern to be matched by REGEXP. RLIKE is the synonym ...
Read more >SQL RegEx | Regular Expressions in MySQL with Examples
A Regular Expression is popularly known as RegEx, is a generalized expression that is used to match patterns with various sequences of ...
Read more >MySQL REGEXP operator - w3resource
REGEXP operator. MySQL REGEXP performs a pattern match of a string expression against a pattern. The pattern is supplied as an argument.
Read more >10 Using Regular Expressions in Database Applications
A regular expression specifies a search pattern, using metacharacters (which are, or belong to, operators) and character literals (described in Oracle Database ...
Read more >Regular Expressions in PostgreSQL - Postgres OnLine Journal
PostgreSQL has a rich set of functions and operators for working with regular expressions. The ones we commonly use are ~, regexp_replace, and ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think that a note on the documentation is enough in this case. It would be a lot of work to try and convert the regexp so I think that we should just render the input verbatim and let the db error if it is not correct
Okay, here’s a feature matrix:
column
matchpattern
?column ~ pattern
column REGEXP pattern
column REGEXP pattern
(requires plugin, but has syntax support)REGEXP_LIKE(column, pattern)
column
matchpattern
usingflags
?column ~ (?flags)pattern
REGEXP_LIKE(column, pattern, flags)
REGEXP_LIKE(column, pattern, flags)
pattern
withreplacement
incolumn
regexp_replace(column, pattern, replacement)
REGEXP_REPLACE(column, pattern, replacement)
REGEXP_REPLACE(column, pattern, replacement)
pattern
withreplacement
incolumn
withflags
regexp_replace(column, pattern, replacement , flags)
REGEXP_REPLACE(column, pattern, replacement, 1, 0, flags)
REGEXP_REPLACE(column, pattern, replacement)
Based on this, I think it makes sense to add the first row (“does
column
matchregex
”) as a core string-column function, but I’m undecided on the other two features. It would still be helpful to users to have them available in a database-independent manner, event though they are less well-supported.