Hello list,
I have the following problem. I wish to query my database to look for
columns with names included in, or including, a given string.
is there a way to do the opposite of "contains", ie, a "contained"
method for string columns? Right now, I am doing the following:

session.query(Parcours).filter(
                             or_(
 
Parcours.parcours_name.ilike('%'+custom_string+'%'),
                                 literal_column("'"+custom_string
+"'").ilike('%'+Parcours.parcours_name+'%'))

this works "ok" for most stuff, but breaks when custom_strings has
quotes and such. Therefore, I need to improve on this:
- either by escaping the custom_string ?
- or by taking another approach than the "ilike" route (I use ilike
instead of contains simply because I don't know how to do case-
insensitive "contains" in PGSQL and my code will have to run both on
sqlite and PGSQL)

also, is there a case-insensitive version of the "contains" method
(which would generate ilike statements instead of like in postgresql
while properly escaping quotes and other stuff) ?

Finally, I am also open to any thoughts and pointers people may have
concerning partial/approaching string matching. At the moment, I just
do this contains/contained, case-insensitive search, and finish with
some manual matching, but if anyone has opinions on this, I am of
course very interested!

Thanks for your time,
Best regards,
Yannick

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to