No way to combine case-insensitive contains() with autoescape
See original GitHub issueMigrated issue, originally created by v (@vr2262)
I would like to filter a query with ILIKE
while escaping special characters like %
and _
. I tried this:
from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
class Example(Base):
__tablename__ = 'example'
id = Column(Integer, primary_key=True)
string_col = Column(String)
session = sessionmaker()()
session.add(Example(string_col='S%mething'))
search_string = 's%'
print(
session.query(Example)
.filter(
func.lower(Example.string_col)
.contains(func.lower(search_string), autoescape=True)
)
)
But I get the error TypeError: String value expected when autoescape=True
because contains()
expects an actual string as the first argument.
Ideally SQLAlchemy would provide this feature out of the box, perhaps with icontains()
or contains(insensitive=True, ...)
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Case insensitive 'Contains(string)' - Stack Overflow
Great string extension method! I've edited mine to check the source string is not null to prevent any object reference errors from occurring...
Read more >Match regular expression (case sensitive) - MATLAB regexp
This MATLAB function returns the starting index of each substring of str that matches the character patterns specified by the regular expression.
Read more >String | Functions | AQL | ArangoDB Documentation
The string matching performed by CONTAINS() is case-sensitive. To determine if or at which position a value is included in an array, see...
Read more >WHERE - Cypher Manual - Neo4j
The CONTAINS operator is used to perform case-sensitive matching regardless of location within a string. Query. Cypher. Query. Copy to Clipboard Run in...
Read more >Impala String Functions
If the argument string to BASE64DECODE() does not represent a valid ... that change how the match is performed, such as i for...
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
Michael Bayer (@zzzeek) wrote:
all you have to do is call lower() on the string:
that’s the beauty of it being a string in the first place.
icontains() is already #3482.
Changes by v (@vr2262):