Re: printing JsonbPair values of input JSONB on server side?

Поиск
Список
Период
Сортировка
От T L
Тема Re: printing JsonbPair values of input JSONB on server side?
Дата
Msg-id CAOb=C0fHdRb0SzG41AHbJXS53hA1MgG7yuV+rO8oAirO2Y744g@mail.gmail.com
обсуждение исходный текст
Ответ на Re: printing JsonbPair values of input JSONB on server side?  (Michel Pelletier <pelletier.michel@gmail.com>)
Список pgsql-general
BTW, my pointer math code was trying to mimic the below code I found for "uniqueifyJsonbObject".

I just removed the logic for dropping duplicates. My difficulty is that I couldn't find out how to interface the jsonb object I get from
my "print_kv_pair()" to this function. Just out of curiosity, I am still interested in finding a way to extract
and feed the JsonValue the right way.

static void
uniqueifyJsonbObject(JsonbValue *object)
{
    bool        hasNonUniq = false;

    Assert(object->type == jbvObject);

    if (object->val.object.nPairs > 1)
        qsort_arg(object->val.object.pairs, object->val.object.nPairs, sizeof(JsonbPair),
                  lengthCompareJsonbPair, &hasNonUniq);

    if (hasNonUniq)
    {
        JsonbPair  *ptr = object->val.object.pairs + 1,
                   *res = object->val.object.pairs;

        while (ptr - object->val.object.pairs < object->val.object.nPairs)
        {
            // Avoid copying over duplicate
            if (lengthCompareJsonbStringValue(ptr, res) != 0)
            {
                res++;
                if (ptr != res)
                    memcpy(res, ptr, sizeof(JsonbPair));
            }
            ptr++;
        }

        object->val.object.nPairs = res + 1 - object->val.object.pairs;
    }
}


On Tue, Mar 19, 2019 at 9:50 AM Michel Pelletier <pelletier.michel@gmail.com> wrote:
Yeah I'm not sure why you're looping using pointer math, the iterators are there to provide that service.  Another function to check out 'jsonb_each', other than the set returning function parts, it does what it looks like your are trying to do.

-Michel

On Mon, Mar 18, 2019 at 4:12 PM Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
>>>>> "T" == T L <tinlyx@gmail.com> writes:

 T> Below is my test. It prints a strange character instead of "a"; and
 T> says that the value isn't numeric.

Yeah, there's plenty else wrong with your code.

Did you look at how JsonbToCStringWorker does it? that looks like the
best example I can find on a quick scan.

--
Andrew (irc:RhodiumToad)

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: subscription broken after upgrade to pg11
Следующее
От: Karl Denninger
Дата:
Сообщение: FreeBSD 12 and Postgres build failures