在GCP Spanner中,对父表执行insert_or_update操作会删除子行吗?

huangapple go评论65阅读模式
英文:

Does insert_or_update on a parent table delete child rows in GCP Spanner?

问题

如果我在一个已经存在的PARENT表中执行insert_or_update(即执行update)操作,Spanner文档中似乎找不到对此的明确答案,那么相应的交错表的现有子行会被删除还是保留?

英文:

I can't seem to find a definitive answer to this in the documentation for Spanner, but if I insert_or_update a row in a PARENT table that already exists (so update) are existing child rows of an interleaved table deleted or preserved?

答案1

得分: 1

insert_or_update 突变将会:

  1. 如果目标表中的行尚不存在,将插入一行新记录。
  2. 如果目标表中的行已存在,将更新现有记录。
  3. 在上述两种情况下都不会触及任何子行。基本上与 insertupdate 的行为相同。

如果您想删除任何子行并用新值替换父行,可以使用 replace 突变类型。

更多详细信息请参考:https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Mutation。

英文:

An insert_or_update mutation will:

  1. Insert a new row in the table that you are operating on if the row does not yet exist.
  2. Update the existing row if the row does exist.
  3. Keep all child rows untouched in both the above scenarios. It basically behaves the same as how insert and update would behave.

You can use the replace mutation type if you want to delete any child rows and replace the parent row with a new value.

See https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.Mutation for more details.

huangapple
  • 本文由 发表于 2023年2月18日 11:03:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定