如何在 cockroachdb 中将列类型从 int8 更改为 bytes?
How can I alter column type from int8 to bytes in cockroachdb?
我有一个非常简单的table即:
CREATE TABLE test(
id INT PRIMARY KEY DEFAULT unique_rowid()
)
我想将 id
类型更改为字节,以便我可以 SET DEFAULT uuid_v4();
。
但是如果我 运行 这个 sql:
ALTER TABLE test MODIFY id bytes;
我遇到一个错误:
pq: cannot convert INT8 to BYTES
是否可以将 cockroachdb 中的 table 列从一种类型更改为另一种类型?
事实证明,cockroach 不允许更改主键约束,所以我所做的只是使用适当的 PK 类型创建新的 table,使用 INSERT INTO SELECT
语句,删除旧的 table 然后改名为新的
官方文档中有:
A table's primary key can only be specified in the CREATE TABLE
statement. It cannot be changed later using ALTER TABLE, though it is
possible to go through a process to create a new table with the new
primary key you want and then migrate the data.
我有一个非常简单的table即:
CREATE TABLE test(
id INT PRIMARY KEY DEFAULT unique_rowid()
)
我想将 id
类型更改为字节,以便我可以 SET DEFAULT uuid_v4();
。
但是如果我 运行 这个 sql:
ALTER TABLE test MODIFY id bytes;
我遇到一个错误:
pq: cannot convert INT8 to BYTES
是否可以将 cockroachdb 中的 table 列从一种类型更改为另一种类型?
事实证明,cockroach 不允许更改主键约束,所以我所做的只是使用适当的 PK 类型创建新的 table,使用 INSERT INTO SELECT
语句,删除旧的 table 然后改名为新的
官方文档中有:
A table's primary key can only be specified in the CREATE TABLE statement. It cannot be changed later using ALTER TABLE, though it is possible to go through a process to create a new table with the new primary key you want and then migrate the data.