Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxx> wrote:
>>>>> "T" == T L <tinlyx@xxxxxxxxx> 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)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux