Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Athena/Presto Split string for In Query

Is it possible to use a comma separated string for an IN query?

I would like to execute the following query using the string a,b,c

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

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

like image 996
hangc Avatar asked Oct 12 '25 04:10

hangc


1 Answers

You can use split(string,delimiter) for splitting string and boolean function contains(array, element) to check if array contains value:

 select * from tablename where contains(split('a,b,c',','),colname)
like image 69
leftjoin Avatar answered Oct 14 '25 19:10

leftjoin