Extract value from a super field

Viewed 28

I have a field event_params that is type super.

Example value of event_params:

[
{"key":"type","value":{"string_value":"blah"}},
{"key":"value","value":{"double_value":5.99}},
{"key":"category","value":{"string_value":"add-ons"}},
{"key":"event_id","value":{"string_value":"956bb654-be90-5334-91a3-ee97074da0eb"}},
]

I would like to get event_id without unfolding the whole thing, I just want to drill down into it and pull up event id.

After reading docs and messing around, I can d0 this:

select
    event_params[4].value,
    event_params[4].key,
    event_params
from "myschema"."mytable"
where event_name = 'purchase'
and event_timestamp = 1660193632449615;

Here I used indexing with 4. But data will not necessarily be in the same order. INstead I want to filter based on the key being event_id.

How can I modify this: event_params[4].key to instead filter based on the name of the key I want, in this case event_id?

0 Answers
Related