Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find records where field value is all LOWERCASE

In a Rails 3.2 app I have a Tag model and want to find all records where the value in the name:string field is all lowercase.

Thus the activerecord query (on Postgres) would return Tag(id: 1, name: 'test') but not Tag(id:2, name: 'Test').

I'm sure there's a straightforward way to do this but I haven't been able to produce a working query!

like image 733
djoll Avatar asked Dec 15 '22 12:12

djoll


1 Answers

This should work:

Tag.where('name = lower(name)')

If name equals lower(name) it means that name is lowercase.

like image 145
Mischa Avatar answered Mar 06 '23 22:03

Mischa