我正在尝试将逗号分隔的字符串转换为整数数组 (integer[]) 以在 Where 子句中使用。
我试过演员, ::Int
没有用。感谢您的意见
例子
Table A | Table B
ID | Set_id
2 | 14,16,17
1 | 15,19,20
3 | 21
我的查询:
Select *
from Table a, table b
where a.id in b.set_id
原文由 sam 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用 unnest() 函数。 unnest 函数用于将数组扩展为一组行。
Select * from Table_a a, table_b b where a.id in (SELECT unnest(string_to_array(b.set_id, ',')::int[]));