Reputation: 1229
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!
Upvotes: 7
Views: 2981
Reputation: 17647
You can use a regular expression to search for all lowercase, like:
Tag.where('name ~ :regex', regex: '^[a-z]+$')
Upvotes: 5
Reputation: 43298
This should work:
Tag.where('name = lower(name)')
If name
equals lower(name)
it means that name
is lowercase.
Upvotes: 12