可以更改 cassandra table 中的列以使其成为静态列吗?

Can a column in a cassandra table be altered to make it static?

我在 cassandra 数据库中有一个 table,其中包含一些静态列,我希望向其中添加另一个静态列。有没有办法改变 table 以便新列是静态的?

假设您的键空间是 key 并且 table 模式是:

 CREATE TABLE p (   
     k text,   
     s text STATIC,   
     i int,   
     PRIMARY KEY (k, i) ); 

然后就可以执行

 ALTER TABLE p ADD f text STATIC;

正如 Will 的回答所指出的,这可能取决于您使用的是哪个版本。 CQL 3.1(Cassandra 2.0 和 2.1)的 ALTER documentation 状态:

These additions to a table are not allowed:

  • Adding a column having the same name as an existing column
  • A static column

虽然显然它适用于 2.1.9。

同样需要注意的是,您不能将现有列更改为静态列。

aploetz@cqlsh:Whosebug> ALTER TABLE bills2 ALTER amount TYPE bigint static;
SyntaxException: <ErrorMessage code=2000 [Syntax error in CQL query] message="line 1:44 missing EOF at 'static' (...bills2 ALTER amount TYPE bigint [static];)">