将字符串数组转换为整数数组

时间:2014-02-11 13:17:24

标签: sql arrays postgresql type-conversion

我有以下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

最后一行中的ids字符串'9755, 9759'可以在sql执行时更改。 我可以将sting转换为这样的数组:

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

但有没有办法将这个字符串数组转换为整数数组?

1 个答案:

答案 0 :(得分:1)

将结果数组转换为int[]

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