I had the same problem with the following setup:
Ubuntu 12.04 + postgres 9.2 + PHP 5.4 + Yii 1.1.
I tried first the fix suggested from Zugluk:
adding in CdbCommandBuilder:208 (i.e. createInsertCommand function)
It works when inserting a new entry in the table but
updates remained a problem.
I also tried to copy past the same code snippet in the
createUpdateCommand but with no results.
After some hours digging around Yii code I was able to
track back to another function: CDbColumnSchema::typecast($value)
CDbColumnSchema is a base class which is extended by database-dependent ones.
In the case of postresql the extended class is called CDbPgsqlColumnSchema.
I fixed the problem as follows:
Copied the function typecast($value) from the base class CDbColumnSchema.
Pasted it in the class CDbPgsqlColumnSchema.
Finally I added a control on the data type at the beginning of the freshly
The final code (that is the one that you have to insert in the CDbPgsqlColumnSchema class)
is the following
* Converts the input value to the type that this column is of.
* @param mixed $value input value
* @return mixed converted value
public function typecast($value)
/*WARNING: I had to add this check:
* when the table column is a boolean there are problems because php
* represents boolean differently and there is a misconversion
* with this modification it seems to work
if($value===TRUE || $value===true || $value === 't' || $value === 'true' ||
$value==='y' || $value==='yes' || $value==='on' ||
$value==='1' || $value===1 )
//END OF MODIFICATION
if(gettype($value)===$this->type || $value===null || $value instanceof CDbExpression)
return $this->type==='string' ? '' : null;
case 'string': return (string)$value;
case 'integer': return (integer)$value;
case 'boolean': return (boolean)$value;
default: return $value;
With this code in place everything seems to work (inserts as well as updates).
You can remove the patch provided by Zugluck as well.