Merge pull request #5382 from citusdata/fix_comma_bug_in_ShardListInserCommand

Fix the extra comma bug in ShardListInsertCommand
pull/5293/head
Halil Ozan Akgül 2021-10-18 13:37:41 +03:00 committed by GitHub
commit 169084f1bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -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, ", ");
}
}
}