I'm working on an RoR project where I have a model with a string attribute that needs to be entirely case insensitive. I'm just wondering what the best way to do this is.

I've seen some cases where people add setters to their models which uppercase the string before it's put in the database, and I've seen some people that make their queries case insensitive when search the database.

Is there a way to do it on the DB level? I'm using postgres. If not, what's the best way to approach this problem? Does the database take a big hit when searching case insensitive? What about from a security perspective? Is it more secure to check case insensitive every time to prevent problems should someone somehow create a lowercase row? Basically, what is best practice on this?