How Can Use Postgresql Array_Append() And Array_Remove() In Yii?

How can use PostgreSQL array_append() and array_remove() in Yii? I am trying to update array type attribute on following table rows-



name UUID[])

Sample data rows: 

1    	NULL

2    	NULL


$books->name='array_append(name, $Name_key_array)';



I have found following error:


CDbCommand failed to execute the SQL statement: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: array value must start with "{" or dimension information"

Also, I already tried few more ways but haven’t found any success. I hope will find some great ideas to fix this issue.

Instead of assigning a SQL expression to the attribute as a string you need to pass it to CDbExpression.

I wouldn’t advise using arrays in the database in this scenario. Quoting the tip from PostgreSQL manual page about arrays:

You should be using a relation instead of an array.


Thanks for reply. I really need a solution to this.

I have tried CDbExpression-


$books->name=new CDbExpression('array_append(name, $Name_key_array)');


but found following error-

CDbCommand failed to execute the SQL statement: SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "{:content:}quot;

Hi All,

I have tried so many ways to use array_append in Yii but no success yet.

Hope, someone will give me right direction.

Thanks to all…

What is $Name_key_array? if it’s php variable, you should double-quote it instead of single-quoting.