Allow references to columns in UPDATE statements

pull/472/head
Brian Cloutier 2016-04-26 07:54:48 -07:00
parent 0ce1e3ddaf
commit 1d1d95f80f
4 changed files with 56 additions and 1 deletions

View File

@ -272,7 +272,7 @@ ErrorIfModifyQueryNotSupported(Query *queryTree)
continue; continue;
} }
if (!IsA(targetEntry->expr, Const)) if (contain_mutable_functions((Node *) targetEntry->expr))
{ {
hasNonConstTargetEntryExprs = true; hasNonConstTargetEntryExprs = true;
} }

View File

@ -0,0 +1,30 @@
CREATE TABLE modifications (
key VARCHAR,
counter INT,
time TIMESTAMPTZ
);
SELECT master_create_distributed_table('modifications', 'key', 'hash');
master_create_distributed_table
---------------------------------
(1 row)
SELECT master_create_worker_shards('modifications', 4, 1);
master_create_worker_shards
-----------------------------
(1 row)
INSERT INTO modifications VALUES ('one', 0, null);
UPDATE modifications SET counter = counter + 1;
ERROR: distributed modifications must target exactly one shard
UPDATE modifications SET counter = counter + 1 WHERE key = 'one';
UPDATE modifications SET time = now() WHERE key = 'one';
ERROR: cannot plan sharded modification containing values which are not constants or constant expressions
SELECT * FROM modifications;
key | counter | time
-----+---------+------
one | 1 |
(1 row)
DROP TABLE modifications;

View File

@ -141,3 +141,9 @@ test: multi_large_shardid
# multi_drop_extension makes sure we can safely drop and recreate the extension # multi_drop_extension makes sure we can safely drop and recreate the extension
# ---------- # ----------
test: multi_drop_extension test: multi_drop_extension
# ----------
# multi_expanded_modifications includes some tests that we can reference columns in
# UPDATEs
# ----------
test: multi_expanded_modifications

View File

@ -0,0 +1,19 @@
CREATE TABLE modifications (
key VARCHAR,
counter INT,
time TIMESTAMPTZ
);
SELECT master_create_distributed_table('modifications', 'key', 'hash');
SELECT master_create_worker_shards('modifications', 4, 1);
INSERT INTO modifications VALUES ('one', 0, null);
UPDATE modifications SET counter = counter + 1;
UPDATE modifications SET counter = counter + 1 WHERE key = 'one';
UPDATE modifications SET time = now() WHERE key = 'one';
SELECT * FROM modifications;
DROP TABLE modifications;