P
P
Pavel2017-10-26 11:03:22
Laravel
Pavel, 2017-10-26 11:03:22

How to add data to JSON column in database without SELECT'a?

Hello. There is a table with a data column with jsonb type. It stores, for example, an array of messages with messages in the dialog. Is it possible to add a new message to the data->messages array without first pulling out the entire dialog, adding a new message to the end of the array, and writing it back to the database? Or is it not feasible by the DBMS itself?
DBMS PostgreSQL

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Talalaev, 2017-10-26
@Palych_tw

Since such a problem has arisen, this is an occasion to think about the correct choice of the database structure, specifically about whether it is worth storing messages this way. But in any case, PostgreSQL was initially designed so that updating a field is always completely overwriting it, so you need to read from there anyway so as not to lose previous records.
Well, there are still guidelines for using this JSON type in postgres , are you sure that your implementation follows them?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question