是否可以重新命名列? [英] Is it possible to rename columns?

查看:171
本文介绍了是否可以重新命名列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能发布类似于

  RENAME COLUMN col1 col2 

在Google Cloud Spanner中?从DDL看来,这是不可能的;如果不是,这是一个设计选择还是限制,而在Beta?

解决方案

不,这是不可能的。目前,您只能对表中的列进行以下操作:




  • 添加一个新的

  • 更改删除行为(级联或不行)

  • STRING 和 BYTES

  • 更改 STRING的长度 BYTES

  • 添加或删除 NOT NULL 修饰符



按照以下步骤操作即可解决问题:


  • 将新列添加到您的表中
  • 更新您的代码以从两列读取
  • 更新您的代码以仅写入新的
  • 运行Cloud Dataflow作业将数据从旧列迁移到新列

  • 更新您的代码以仅从新列

  • 删除旧列



请记住,上述步骤对于t他是主键列,你必须通过创建一个新表来完成数据迁移。


Is it possible to issue something like

RENAME COLUMN col1 col2

in Google Cloud Spanner? It looks from the DDL that this isn't possible; if not, is this a design choice or a limitation whilst in Beta?

解决方案

No, this is not possible. Currently you can only do the following with regard to altering columns in a table:

  • Add a new one
  • Delete an existing one, unless it's a key column
  • Change delete behavior (cascading or not)
  • Convert between STRING and BYTES
  • Change length of STRING and BYTES
  • Add or remove NOT NULL modifier

A work around is possible by following these steps in order:

  • Add the new column to your table
  • Update your code to read to from both columns
  • Update your code to only write to the new one
  • Run a Cloud Dataflow job to migrate the data from the old column to the new column
  • Update your code to only read from the new column
  • Drop the old column

Keep in mind the above steps will not work for the primary key column, you'll have to do by creating a new table, and doing the data migration that way.

这篇关于是否可以重新命名列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆