Presto array contains an element that likes some pattern

╄→尐↘猪︶ㄣ 提交于 2020-01-22 12:50:05

问题


For example, one column in my table is an array, I want to check if that column contains an element that contains substring "denied" (so elements like "denied at 12:00 pm", "denied by admin" will all count, I believe I will have to use "like" to identify the pattern). How to write sql for this?


回答1:


Use presto's array functions:

  • filter(), which returns elements that satisfy the given condition
  • cardinality(), which returns the size of an array:

Like this:

where cardinality(filter(myArray, x -> x like '%denied%')) > 0



回答2:


See array operator docs here

contains(array_column,'denied')



来源:https://stackoverflow.com/questions/50766928/presto-array-contains-an-element-that-likes-some-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!