How to create RPC function that will update json column? #2373
-
I have a JSON column where I want to store an array of objects. Looking at #465 I'm not sure whether PATCH has been implemented yet for json columns, though someone mentions that it's possible to create an .rpc() function to manually handle it from the database level. Say for example it's an array with between 0 and 5 objects, I'd want the ability to either update a specific object or insert an object if not present. What would a function like this look like? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes, the PATCH method will update the whole JSON column. To update just parts of it, you could use Please provide a bit more details on how you will be updating / inserting the fields inside the |
Beta Was this translation helpful? Give feedback.
Yes, the PATCH method will update the whole JSON column. To update just parts of it, you could use
jsonb_set
in a function, but it will require the exact index in the array.Please provide a bit more details on how you will be updating / inserting the fields inside the
json
array because I can't see an straight forward way to do so in PostgreSQL (or maybe I'm missing something).