Yii Framework Forum: A Helpful Suggestion For Postgres And Cgridview - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

A Helpful Suggestion For Postgres And Cgridview A way to make case insensitivity work at the DB level Rate Topic: -----

#1 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 09 May 2013 - 09:10 PM

Hi all,

I just spent about 30 minutes trying to figure out a way around tons of coding work to either ILIKE everything or to LOWER() everything to be able to do case insensitive comparisons in Postgres (mainly so my CGridView filters would work out of the box). I also saw some people posting in the forum, but I did not see this solution posted. I thought I would add it in case it helps someone.

I figured out that citext comes prepackaged with most postgres installs, but not enabled. You can simply do the following to make this happen:

- Open pgadmin

- Connect to the server and database you are using

- Open an sql window

- Run the command (without quotes): "CREATE EXTENSION citext;"

- Change any column types in your tables from character varying or text to citext

Now all of your datagrid filter stuff will work! The only downside is that you can never do case sensitive comparisons on these columns that you changed to citext, but I never need to do that anyway.

Hope this helps someone with CGridView Filter case insensitivity problems while using Postgres!
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 711
  • Joined: 02-July 10
  • Location:Central Poland

Posted 10 May 2013 - 03:21 AM

you may also override CDbCriteria and overload addSearchCondition and compare functions changing LIKE to ILIKE and NOT LIKE to NOT ILIKE. then use this new criteria class in your search() function in model classes.

I think it is better solution because you can still search with case sensitive operators.
red
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users