How to update any field in a json of type json? It should accept an object or an array of key(s) and update the key if it exists else create

Generic function in nodejs and Postgres to update a key in JSON column of type JSON in Postgres.

I have tried the below query:

update contacts set contact_data = jsonb_set(contact_data, '{order_id}', '${order_date}', '${product_name}') where id = ${id};

But the issue is every time I need to specify the keys. I need something generic, something that accepts a set of keys and updates them. The keys may vary every time the function gets called.

I am trying to avoid looping as each time the update is triggered, Postgres re-writes the entire row or at least that's what I know.

Please let me know if you need more clarifications regarding the question. Thanks.



from Recent Questions - Stack Overflow https://ift.tt/3nyNoRo
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations