diff --git a/src/backend/distributed/deparser/citus_ruleutils.c b/src/backend/distributed/deparser/citus_ruleutils.c index ada77b098..04591fae0 100644 --- a/src/backend/distributed/deparser/citus_ruleutils.c +++ b/src/backend/distributed/deparser/citus_ruleutils.c @@ -1391,7 +1391,7 @@ convert_aclright_to_string(int aclright) /* * contain_nextval_expression_walker walks over expression tree and returns - * true if it contains call to 'nextval' function. + * true if it contains call to 'nextval' function or it has an identity column. */ bool contain_nextval_expression_walker(Node *node, void *context) @@ -1401,6 +1401,13 @@ contain_nextval_expression_walker(Node *node, void *context) return false; } + /* check if the node contains an identity column */ + if (IsA(node, NextValueExpr)) + { + return true; + } + + /* check if the node contains call to 'nextval' */ if (IsA(node, FuncExpr)) { FuncExpr *funcExpr = (FuncExpr *) node; diff --git a/src/test/regress/expected/generated_identity.out b/src/test/regress/expected/generated_identity.out index 23a87af3d..b484dda1b 100644 --- a/src/test/regress/expected/generated_identity.out +++ b/src/test/regress/expected/generated_identity.out @@ -522,4 +522,21 @@ INSERT INTO color(color_name) VALUES ('Red'); \c - - - :master_port SET search_path TO generated_identities; SET client_min_messages to ERROR; +DROP TABLE IF EXISTS test; +CREATE TABLE test (x int, y int, z bigint generated by default as identity); +SELECT create_distributed_table('test', 'x', colocate_with := 'none'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +INSERT INTO test VALUES (1,2); +INSERT INTO test SELECT x, y FROM test WHERE x = 1; +SELECT * FROM test; + x | y | z +--------------------------------------------------------------------- + 1 | 2 | 1 + 1 | 2 | 2 +(2 rows) + DROP SCHEMA generated_identities CASCADE; diff --git a/src/test/regress/sql/generated_identity.sql b/src/test/regress/sql/generated_identity.sql index 004f45b40..83c16eaa8 100644 --- a/src/test/regress/sql/generated_identity.sql +++ b/src/test/regress/sql/generated_identity.sql @@ -263,4 +263,11 @@ INSERT INTO color(color_name) VALUES ('Red'); SET search_path TO generated_identities; SET client_min_messages to ERROR; +DROP TABLE IF EXISTS test; +CREATE TABLE test (x int, y int, z bigint generated by default as identity); +SELECT create_distributed_table('test', 'x', colocate_with := 'none'); +INSERT INTO test VALUES (1,2); +INSERT INTO test SELECT x, y FROM test WHERE x = 1; +SELECT * FROM test; + DROP SCHEMA generated_identities CASCADE;