From e3446692f301aaeeeaa196914d5b415aa46bad05 Mon Sep 17 00:00:00 2001 From: Halil Ozan Akgul Date: Fri, 15 Oct 2021 18:42:23 +0300 Subject: [PATCH] Fix the bug by adding comma before the values --- .../distributed/metadata/metadata_sync.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index f242a687f..6e305ef62 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -923,6 +923,7 @@ ShardListInsertCommand(List *shardIntervalList) "shardlength, groupid, placementid) AS (VALUES "); ShardInterval *shardInterval = NULL; + bool isFirstValue = true; foreach_ptr(shardInterval, shardIntervalList) { uint64 shardId = shardInterval->shardId; @@ -931,6 +932,16 @@ ShardListInsertCommand(List *shardIntervalList) ShardPlacement *placement = NULL; foreach_ptr(placement, shardPlacementList) { + if (!isFirstValue) + { + /* + * As long as this is not the first placement of the first shard, + * append the comma. + */ + appendStringInfo(insertPlacementCommand, ", "); + } + isFirstValue = false; + appendStringInfo(insertPlacementCommand, "(%ld, %d, %ld, %d, %ld)", shardId, @@ -938,16 +949,6 @@ ShardListInsertCommand(List *shardIntervalList) placement->shardLength, placement->groupId, placement->placementId); - - if (!(llast(shardPlacementList) == placement && - llast(shardIntervalList) == shardInterval)) - { - /* - * As long as this is not the last placement of the last shard, - * append the comma. - */ - appendStringInfo(insertPlacementCommand, ", "); - } } }