Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Presto array contains an element that likes some pattern

Tags:

sql

presto

trino

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?

like image 872
daydayup Avatar asked Jun 08 '18 19:06

daydayup


People also ask

What is Array_join in SQL?

This is the function to use if you want to concatenate all the values in an array field into one string value. You can specify an optional argument as a separator, and it can be any string. If you do not specify a separator, there will be nothing aded between the values.

Is null in Presto?

The IS NULL and IS NOT NULL operators test whether a value is null (undefined). Both operators work for all data types.

What is Presto database?

Presto is an open source, distributed SQL query engine designed for fast, interactive queries on data in HDFS, and others. Unlike Hadoop/HDFS, it does not have its own storage system. Thus, Presto is complimentary to Hadoop, with organizations adopting both to solve a broader business challenge.


1 Answers

In newer versions of PrestoSQL (now known as Trino), you can use the any_match function:

WHERE any_match(column, e -> e like '%denied%')
like image 173
Martin Traverso Avatar answered Sep 28 '22 05:09

Martin Traverso