dshgdhdfcas30210 2013-12-06 13:36
浏览 390

如何在Yii中使用Postgresql Array_Append()和Array_Remove()?

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

CREATE  TABLE Books(
id INT NOT NULL PRIMARY KEY,  
name UUID[])

Sample data rows: 
1       NULL
2       NULL

$books=Books::model()->findByPk($id);
$books->name='array_append(name, $Name_key_array)';
$books->save();

I have found following error:

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

But If I use array directly then its work but not when using variable name i.e.

array_append({1,2,3}, {4})

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

  • 写回答

1条回答 默认 最新

  • drrkgbm6851 2013-12-06 16:00
    关注

    I think you are using the array_append() in other way. it should be like this

    SELECT array_append(ARRAY[1,2], 3);
     array_append
    --------------
     {1,2,3}
    (1 row)
    

    So if i correct yours, it should be

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

    for removing elements from an array, check this solution: http://www.youlikeprogramming.com/2013/06/removing-values-from-a-postgresql-array/

    to an array in PostgreSQL data must be inserted in the following way,

    INSERT INTO table (arr_col) VALUES ('{val1,val2, val3}');
    

    http://www.postgresql.org/docs/9.1/static/arrays.html

    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备