I have to generate a dynamic sql query for inserting values to the below table from a json.
Eg: demo_table(id, key1,key2,key3,key4,key5,value1,value2,value3,value4,value5)
json – data = {"rows":["test_id":11,"score":100,"name":"test"]}
the insert statement will be like below,
insert into demo_table(key1,key2,key3,value1,value2,value3)values("test_id",score,"name":11,"100":"test")
based on the number of elements in the json, the query have to dynamically adjust. since the max number of columns are key5 and value5, based on the number of json elements, the others columns we can set to null.
anyone have any ideas on this one, i tried many options and found many errors on the way.
Any help would be really appreciated. thanks in advance