K
K
kommov2019-03-22 20:46:30
SQLite
kommov, 2019-03-22 20:46:30

How to make a mass update/insert in SQLite without nulling fields not specified in the query?

I ask the help of SQLite experts in solving the following problem :)
There is a table Table1. It has 4 columns: id (unique), doc, name, info:
5c951c67679ca736068707.png
For example, it contains the following values:
5c951ca965f30636800231.png
I need to do a mass update of the fields SPECIFIED in the request. I do it like this:
5c951edf0e535531328339.png
Everything would be fine, but only all fields not specified, in this case, are reset to zero. Result after the query:
5c951ef5887c0533082313.png
As you can see, the info column has become null. Is there a way to make the update or insert work only for the specified fields? The variant with one request for each id is not suitable. Also, getting the values ​​of unspecified columns beforehand will also fail, since all the data is pulled in from the outside.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Solovyov, 2019-04-22
@Dreddsa

UPDATE Table1 SET name = ‘newname1’ WHERE id = 1;
And so on...
And so you only insert (replace) lines, but do not update values.
For bulk modification in this particular example:
Finally, check out the sqlite3 marginal notes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question