Home > Software design >  how to update and append values to array in google spanner
how to update and append values to array in google spanner

Time:12-03

I have a column with data type Array(String) in spanner. How can I append value to an array for update queries

I'm able to update the values using this command

update CarTable set models = ["BMW","HONDA"] WHERE year = "2020"

But the problem with this update is it overrides the previous values. I want to append these values to the ones that are already present. Is there any command that takes care of this requirement?

CodePudding user response:

You can use the ARRAY_CONCAT function for that:

update CarTable set models = ARRAY_CONCAT(models, ["BMW","HONDA"]) WHERE year = "2020"
  • Related