2

Tablename:-table_data_set, Columnname:-info

data format:

{
   "al_uri":"https://al/ma/np_6101",
   "parameters":[
      {
         "file_name":"QPR.AP6101_%Y%m%d",
         "input_format":"fixed",
         "output_format":"parquet",
         "delimiter":"None",
         "extension":".dat",
         "header":0,
         "footer":0,
         "date_pattern":"%Y%m%d%H%M%S",
         "type":"incremental"
      }
   ]
}

How to extract QPR.AP6101_%Y%m%d from the array. Tried below query, but not returning data.

select name,info ->> 'al_uri' as URL,info -> 'parameters' ->> 'file_name' as filename 
from table_data_set;

1 Answer 1

5

The -> operator also has a version where the right hand argument is an integer, that will select the corresponding array element.

So you want:

select name,
       info ->> 'al_uri' as URL,
       info -> 'parameters' -> 0 ->> 'file_name' as filename 
from table_data_set;

info -> 'parameters' -> 0 picks the first array elements from parameters

A slightly shorter version is the #>> operator which accepts a path to an element:

input #>> '{parameters,0,file_name}' as file_name
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.