2016-09-16 29 views
1

你好我正在写一个pgsql函数,并且在这个函数中,我有一个请求与array_to_string方法。Postgresql请求wtith array_to_string

AND id NOT IN (array_to_string(excludeArcs,',')) 

ID是一个整数,但array_to_string返回字符串这样: 错误结果: 操作符不存在整数<>文本

有人能帮助我吗?

回答

1

您的查询等于id NOT IN('1,2,3')。您无法将ID与字符串进行比较。

有必要展开数组表:

AND id NOT IN(select * from unnest(excludeArcs)) 
0

串的转变是错误的 - 字符串的操作更加昂贵

postgres=# select 10 = ANY(ARRAY[10,20,30]); 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ t  │ 
└──────────┘ 
(1 row) 

postgres=# select 10 <> ALL(ARRAY[10,20,30]); 
┌──────────┐ 
│ ?column? │ 
╞══════════╡ 
│ f  │ 
└──────────┘ 
(1 row)