skip to Main Content

I am trying to get the source and target where source is 270 and the column is jsonb and values like

[{"source": 270, "target": 285}, 
 {"source": 427, "target": 285}, 
 {"source": 285, "target": 285}]

The expected output is {"source": 270, "target": 285}

2

Answers


  1. Chosen as BEST ANSWER

    It is working If I use the following Query. Here links is the column name.

    select links from (select jsonb_array_elements(links) as links from supply_chain_graph) as foo where links->>'source'='270'


  2. You can use a JSON path query:

    select jsonb_path_query_first(the_column, '$[*] ? (@.source == 270)')
    from the_table;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search