Postgresql join on jsonb -


i have tables.

orders table:

id: integer items: jsonb 

items table:

id: integer title: string price: integer 

example order record

id: 1,  items: {    "1"=>{"qty"=>3},    "3"=>{"qty"=>12}     } 

example items records

 id:1, title: "tesla model s"  id:2, title: "tesla model w"  id:3, title: "tesla model d" 

please, result:

id:1, title: "tesla model s", qty: 3 id:3, title: "tesla model d", qty: 12 

in end, did. query works.

        select         json_data.key id,          json_data.value::jsonb->'qty' qty,         items.title title          orders, jsonb_each_text(orders.items) json_data         inner join items on items.id = json_data.key::int         orders.id=1 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -