P
P
postgresdev2019-07-18 18:15:33
PostgreSQL
postgresdev, 2019-07-18 18:15:33

How to find a specific value in an array of arrays in Postgresql?

You need to find all sku whose value is 735215.
An example of json is in the config column:

"stockLevels":[
{"sku":"156320","stock":0,"deliveryTimescale":{"min":5,"max":5}},
{"sku":"156322","stock":0,"deliveryTimescale":{"min":1,"max":1}},
{"sku":"156323","stock":0,"deliveryTimescale":{"min":1,"max":1}},
{"sku":"156350","stock":0,"deliveryTimescale":{"min":5,"max":5}},
{"sku":"156351","stock":0,"deliveryTimescale":{"min":5,"max":5}},
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Edward, 2019-07-21
@kalter1808

select * from your_table, 
jsonb_to_recordset((select your_table.config)->'stockLevels') 
as t (sku int, stock int, deliveryTimescale jsonb) 
where sku = 735215;

There are json functions for all occasions:
https://postgrespro.ru/docs/postgresql/11/function...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question