Skip to content
Advertisement

How to grab the value from JSON object in Postgresql and insert into some other tables?

implement

-> grab value of orderId/fulfillerId/orderDetailsUrl and perform iteration for item array object to grab required values as its array of similar objects

-> Store in a variable

-> then perform the insert operation

Somehow its not working

Desired Output:

Item Table

  • itemId

  • fullfillerId

  • orderId

  • skuCode

++ all remaining data from JSON in Item Table

ItemDetails Table

  • itemId

  • orderDetailsUrl

  • taskId

  • quantity

I have tried various jsonb formatting but exact output is not achieved after parsing, I am not able to pick values from JSON and use Insert query

Advertisement

Answer

Here is a plpgsql block for illustration how you may do it. raise notice would be replaced with the relevant command(s), insert for example.

An insert will be simpler, w/o a loop:

As a function that inserts into item table and itemietails table:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement