1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-27 00:12:01 +03:00

Fix JSON_OBJECTAGG uniquefying bug

Commit f4fb45d15c contained a bug in removing items with null values when
unique keys are required, where the leading items that are sorted
contained such values. Fix that and add a test for it.

Discussion: https://postgr.es/m/CAJA4AWQ_XbSmsNbW226UqNyRLJ+wb=iQkQMj77cQyoNkqtf=2Q@mail.gmail.com
This commit is contained in:
Andrew Dunstan
2022-04-28 15:28:20 -04:00
parent 5c854e7a2c
commit 9c3d25e178
3 changed files with 22 additions and 2 deletions

View File

@@ -1959,8 +1959,18 @@ uniqueifyJsonbObject(JsonbValue *object, bool unique_keys, bool skip_nulls)
if (hasNonUniq || skip_nulls)
{
JsonbPair *ptr = object->val.object.pairs + 1,
*res = object->val.object.pairs;
JsonbPair *ptr, *res;
while (skip_nulls && object->val.object.nPairs > 0 &&
object->val.object.pairs->value.type == jbvNull)
{
/* If skip_nulls is true, remove leading items with null */
object->val.object.pairs++;
object->val.object.nPairs--;
}
ptr = object->val.object.pairs + 1;
res = object->val.object.pairs;
while (ptr - object->val.object.pairs < object->val.object.nPairs)
{