New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using filter on lower-cased columns #560

Closed
freiguy1 opened this Issue Dec 30, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@freiguy1

freiguy1 commented Dec 30, 2016

I'm looking to perform a query similar to

SELECT things FROM table1 where LOWER(table1.name) LIKE '%something%';

In rust with diesel, I get this close:

try!(table1::table.filter(table1::name.like(query)).load::<Table1>(&conn));

Is there a way I can use diesel to compare with LIKE against a lower case version of the columns? Is regex an option? I'd prefer to not have to make another column which is the lower case version of an existing column.

Thanks!

@sgrif

This comment has been minimized.

Member

sgrif commented Jan 3, 2017

We don't have the lower function built in yet. I'd certainly accept a pull request that adds one. We provide the sql_function! macro as well which would allow you to just define the function locally like so:

sql_function!(lower, lower_t, (a: types::VarChar) -> types::VarChar);

try!(table1::table.filter(lower(table1::name).like(query)).load::<Table1>(&conn));

@sgrif sgrif closed this Jan 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment