- Newest
- Most votes
- Most comments
In case someone else is stumbling about this issue i found a solution.
I had to first convert the array into a string and this worked perfectly with array_join i thought about casting it to the correct type using cast() before but without any success.
I was able to get the length then via length(array_join(Options, ','))
select "Options", (LENGTH(array_join(Options,',')-LENGTH(array_join((Options, ''))+1 as "Number of Options"
Maybe this helps someone else cause it really took me forever to find a solution to this (Thanks to Guru Stron on Stackoverflow :) ).
you may have to use a combination of "regexp_like" (which evaluates every comma to true) along with "count" to count number of true occurrences. Here is a quick guide to presto regex documentation: https://prestodb.io/docs/0.217/functions/regexp.html
You can split the string into an array and then return the number of items:
select cardinality(split('x123A, x5894B, z567D', ',')) as options
When you run it against a table, you can replace 'x123A, x5894B, z567D' with the column name, but the above query returns '3' for me.
Relevant content
- asked 2 years ago
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago