用于 In Query 的 Athena/Presto 拆分字符串

Posted

技术标签:

【中文标题】用于 In Query 的 Athena/Presto 拆分字符串【英文标题】:Athena/Presto Split string for In Query 【发布时间】:2021-05-07 11:35:03 【问题描述】:

IN 查询是否可以使用逗号分隔的字符串?

我想使用字符串a,b,c执行以下查询

select * from tablename where colname in ('a', 'b', 'c')

示例 - select * from tablename where colname in (split_string('a,b,c'))

【问题讨论】:

【参考方案1】:

您可以使用split(string,delimiter) 分割字符串和布尔函数contains(array, element) 来检查数组是否包含值:

 select * from tablename where contains(split('a,b,c',','),colname)

【讨论】:

以上是关于用于 In Query 的 Athena/Presto 拆分字符串的主要内容,如果未能解决你的问题,请参考以下文章