Case-insensitive select

1,774 views
Skip to first unread message

RVince

unread,
Aug 31, 2011, 8:27:30 AM8/31/11
to sqlalchemy
I'm using Postgres and the end-users are complaining that the search
features provided by the web app are case-sensitive (via Postgres). Is
there a way to do a case-insensitive version of select statements? Not
all statements are of the form "=" or "like" but often of the form
"...where lastname >= 'smith';" Is there a way to do this type of case-
insensitive comparison at the SQLAlchemy level? Thanks RVince

Michael Bayer

unread,
Aug 31, 2011, 5:56:54 PM8/31/11
to sqlal...@googlegroups.com

Usually like this:

from sqlalchemy import func
query(Widget).filter(func.lower(Widget.name) == func.lower("Some name"))

if you're using "LIKE", you can use ILIKE instead which is built in:

Widget.name.ilike("Some Expression")

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

Reply all
Reply to author
Forward
0 new messages