2014-02-11 216 views
0

的陣列我有以下SQL:轉換字符串數組爲整數

SELECT * FROM (SELECT t.id, t.summary, null as worker, tt.worked from ticket t 
INNER JOIN (SELECT ticket, sum(seconds_worked)/3600.0 as worked FROM ticket_time GROUP BY ticket) tt ON tt.ticket=t.id 
UNION ALL 
SELECT ticket,null, tt.worker, sum(tt.seconds_worked)/3600.0 from ticket_time tt GROUP BY ticket,worker) as foo 
WHERE id in ('9755, 9759') ORDER BY id 

在最後一行每當SQL執行能夠而且將會改變的ID字符串'9755, 9759'。 我能刺痛轉換爲一個這樣的數組:

string_to_array('9755, 9759', ',') 

但是,有沒有辦法這個字符串數組轉換成整數數組?

回答

1

結果數組只投給int[]

where id = ANY (string_to_array('9755, 9759', ',')::int[]) 
+0

謝謝!我知道psql並試圖將其轉換爲:: int4來代替。 – konart

+0

或者首先使用'ARRAY'文字,例如'ANY(ARRAY [9755,9759])' –

+0

這就是問題所在 - 我在這裏工作的系統的核心不能傳遞任何東西,除了一個字符串,所以我必須從中創建一個數組。 – konart