CitusDB:不允许修改行的分区值

时间:2016-11-12 07:57:53

标签: postgresql citus

我想更新或删除测试数据库上的数据使用基于postgressql的citus,它注意到我这个信息: 不允许修改行的分区值 西特斯:6.0 PostgreSQL的:9.6 当我使用citus时,如何更新或删除数据?

1 个答案:

答案 0 :(得分:1)

我认为错误信息在这种情况下有点令人困惑。不允许更新分发键值本身,但是,允许通过证明分发键值来更新/删除行。请参阅以下示例:

CREATE TABLE test_table (key int, value text);

-- distribute the table
SELECT create_distributed_table('test_table', 'key');

-- insert a row
INSERT INTO test_table VALUES (1, 'some test');

-- get the inserted row
SELECT * FROM test_table WHERE key = 1;

-- now, update the row
UPDATE test_table SET value = 'some another text' WHERE key = 1;

-- get the updated row
SELECT * FROM test_table WHERE key = 1;

-- now delete the row
DELETE FROM test_table WHERE key = 1;

-- see that the row is delete
SELECT * FROM test_table WHERE key = 1;

现在,让我举一个不允许的例子。不允许更新分发键值,因为该行已基于该值放置在分片上,并且更新该值可能最终导致该行不在该分片中。

-- insert the row again
INSERT INTO test_table VALUES (1, 'some test');

-- now, try to update the distribution key value
UPDATE test_table SET key = 2 WHERE key = 1;
ERROR:  modifying the partition value of rows is not allowed

希望这有帮助。