Topic: postgreSQL sort by name but ignoring case?

Hi,  I currently have:

@tags = Tag.find_by_sql('select tags.id, name, count(distinct taggable_id) from taggings join tags on (tags.id=taggings.tag_id) group by name, tags.id order by name')

but it results in:

Apple
Bear
Cat
Zebra
dog
fawn
hexadecimal

Is there a way to sort through this without case sensitivity?

-patrick

Last edited by patrick99e99 (2006-12-06 22:51:09)

Re: postgreSQL sort by name but ignoring case?

Nevermind, I figured it out..  I just added at the end "tags.id order by lower(name)" and that did it.

-patrick

Re: postgreSQL sort by name but ignoring case?

Just remember that lower() is database-specific, so if you use anything other than postgresql that statement will throw an exception/error.

vinnie - rails forum admin

Re: postgreSQL sort by name but ignoring case?

Do you know which databases don't support lower()? I always thought it was fairly universal. I know MySQL and SQLite support it.

Railscasts - Free Ruby on Rails Screencasts

Re: postgreSQL sort by name but ignoring case?

ryanb wrote:

Do you know which databases don't support lower()? I always thought it was fairly universal. I know MySQL and SQLite support it.

Nevermind. I was thinking SQL server because it has lcase/ucase functions but apparently upper and lower work there too.

vinnie - rails forum admin