Skip to content
Advertisement

Presto – How to convert a field with map to rows

I’m new to Presto SQL and I am stuck to a issue and I really need your help.

I have a table with a field “Info”:

I want to pull all order_id(s) and convert them as rows, the output may look like this:

My query:

I tried the query above but it can only returns the order_id as an array. Anyone know how to do it? Thank you so much and I appreciate your help!

Advertisement

Answer

Documentation is you friend. You are interested in json functions and unnest (in the code sample succinct version of syntax is used). In addition to this there is one trick – "[333222, 444555, 777888]" is a double encoded json array, so you need to parse it two times (first one is done by json_extract_scalar):

Output:

Date order_id
2021-01-01 333222
2021-01-01 444555
2021-01-01 777888

UPD

To address your question in the comments:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement