Need Help With Yii - Postgresql

Hi every one. This is the first time I use yii with postgresql, and I got this error when I try to search in cgridview search column :

Error 500: <h1>CDbException</h1>

<p>CDbCommand failed to execute the SQL statement: SQLSTATE[42883]: Undefined function: 7 ERROR:  operator does not exist: timestamp without time zone ~~ unknown

LINE 1: ...FROM "tbl_product_request" "t" WHERE expired_date LIKE '%test%'


HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.. The SQL statement executed was: SELECT COUNT(*) FROM "tbl_product_request" "t" WHERE expired_date LIKE :ycp0. Bound with :ycp0='%d%' (D:\xampp\htdocs\yii-1.1.12\framework\db\CDbCommand.php:528)</p><pre>#0 D:\xampp\htdocs\yii-1.1.12\framework\db\CDbCommand.php(425)

The column’s data type is datetime, and it seems like the problem is the generated query tries to compare datetime data type column with string. Anybody has the solution ? Please help. Thanks

show me your code of model search function

This is my search function :

public function search()


		$criteria=new CDbCriteria;














		return new CActiveDataProvider($this, array(




Like you say the problem is trying to compare a date time with a string, but if you don’t wanna errors at moment of the search you may put the same format of the database column at the search field or use a calendar to do it.

If you wanna use a calendar you can view

but the guide is in spanish

You shouldn’t use compare() on datetime fields (resulting operator would be LIKE instead of ‘=’).

Use addCondition for example.

Hi, so sorry for the late reply, been sick and bed rest since two days ago and just getting well today.

I used to use mysql and the compare method works well, even though the datatype is datetime. But I think I cant do that with postgre and the solution would be using addCriteria on my search function. Thanks for the solution, helps me a lot

Yeah, MySQL allows users to do a lot of nasty things. That’s how it works.

PG is way more restrictive, but it’s awesome DB.