0

I want to update a column with many values its of type json but when i do my previous data got

const value = await knexas("orders")
  .update({
    delivery_status: JSON.stringify(delivery_status),
    source_latlong: JSON.stringify(source_latlong),
  })
  .where({ order_id: req.params.order_id });

and i am also trying to insert but istead of getting those values updated in spefic order id new random order id i genereated

const update = await knexas("orders")
  .insert({
    route_latlong: JSON.stringify(source_latlong),
  })
  .where({ order_id: req.params.order_id });
Legion
  • 1
  • 1
    Does this answer your question? [What are differences between INSERT and UPDATE in MySQL?](https://stackoverflow.com/questions/2002500/what-are-differences-between-insert-and-update-in-mysql) – Luuk Oct 06 '22 at 17:52
  • no that diffrence i know my second part of question is that i even tried to insert it in specfic column of a row but isted of data geeting saved in that order id a new random order id get generated and data is saved in that row – Legion Oct 06 '22 at 17:55
  • Insert/Update do things with records, Insert is creating a new record, Update is updating a record. When you want to change the value of a field in an existing record, you need to do update. (and you should update it with the changed value. i.e. a field has the value 2 (let's say its an integer) when you update it with 6 then it will contain 6, but if you want to add 6 to the current value, you should get (2+6=) 8. – Luuk Oct 06 '22 at 19:22

0 Answers0