PostgreSQL array_remove在BIGINT ARRAY上

时间:2018-04-17 14:26:36

标签: postgresql

我正在尝试从BIGINT数组中删除一个项目,所以很自然地我尝试了:

update MyTABLE
set MyBigIntArray= array_remove(MyBigIntArray,1)
where id=10

但是Postgresql(试过9.5和10.0)回复我:

  

提示:没有函数匹配给定的名称和参数类型。您   可能需要添加显式类型转换。错误:功能   array_remove(bigint [],整数)不存在

即使它通常接受anyarray:array_remove(anyarray,anyelement) ,src:Postgres DOC

唯一能使它工作的是将bigint []强制转换为int []:

update MyTABLE
set MyBigIntArray= array_remove(MyBigIntArray::int[],1)
where id=10

有没有办法以简单的方式做到这一点? (我发现了一些plsql / SQL函数)

1 个答案:

答案 0 :(得分:1)

您还需要将1转换为bigint

[local] #= SELECT array_remove(ARRAY[1::bigint], 1);
ERROR:  42883: function array_remove(bigint[], integer) does not exist
LINE 1: SELECT array_remove(ARRAY[1::bigint], 1);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
LOCATION:  ParseFuncOrColumn, parse_func.c:523
[local] #= SELECT array_remove(ARRAY[1::bigint], 1::bigint);
┌──────────────┐
│ array_remove │
├──────────────┤
│ {}           │
└──────────────┘
(1 row)
相关问题