Amazon Timestream - can I select an array element from a measure_value

Viewed 18

I have a measure_value::varchar that is say [32603072,20213608,1314736] and named memory.

How would I select the 1st element of that array only ?

1 Answers

You can use a combination of string functions to convert into array, like

  • replace to remove brackets
  • split to parse the objects

Then you can use normal array operators. Example here

select my_array[1] from (
    select 
        split(replace(replace(my_string,'[',''),']',''), ',') as my_array 
    from (
        select '[32603072,20213608,1314736]' as my_string
    )
)

Result:

|_col0|

| 32603072|

to make replace simpler, maybe you also can try regexp_replace() to remove the brackets first, but I am not too familiar how to write this expression

Related