0

I have a table with simple & complex entries:

id | formats | ...
1   [array]
2   [array]
...

I can select the rows I want based on some other columns. The [array] is a list of complex entries

formats:
  [{
    format: "blah1"
    hash_key: "hash_key1"
  },
  {
    format: "blah2"
    hash_key: "hash_key2"
  },{
    format: "correct"
    hash_key: "hash_key3"
  },
  ...
  ]

I need to loop through the the list of formats and if format=="correct" select the hash_key. So I will return all of my rows with:

id1, hashkey
id2, hashkey
...

I don't know how this can be done in SQL. This would be easy with a while loop in C++ or Python, but I need to do it in SQL here. I need to do this in Spanner SQL as this might matter. I can try any standard SQL answers.

2
  • 2
    Which DBMS product are you using? Postgres? Oracle? Commented Jan 11, 2021 at 21:33
  • If you're using SQL Server, the OPENJSON method is what you're looking for Here is an example. Commented Jan 11, 2021 at 21:34

0

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.