1

I am using Postgresql 9.5

I have two tables(product and product_temp) with jsonb colums

I would like to insert the values from product_temp to product

but the name of the data inside the json is not equal ex:

INSERT INTO product(data1->>'__COD__', data1->>'__PAGE__', job_id) 
 SELECT data2->>'cod', data2->>'page', job_id 
 FROM product_temp where someid = '123'
asked Oct 19, 2016 at 21:47

1 Answer 1

4

Quickly did lots of testing and i got what you wanted.

INSERT INTO product(data1, job_id)
SELECT json_build_object('__COD__',data2->>'cod','__PAGE__',data2->>'page') data1, job_id FROM product_temp;

Your data1 is one column. Tested with PostgreSQL 9.5

answered Oct 20, 2016 at 0:24
1
  • 1
    OW Perfect answer! Commented Oct 20, 2016 at 1:14

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.