2016-09-16 21 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)