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

From: T L <tinlyx(at)gmail(dot)com>
To: Michel Pelletier <pelletier(dot)michel(at)gmail(dot)com>
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: printing JsonbPair values of input JSONB on server side?
Date: 2019-03-19 18:20:04
Message-ID: CAOb=C0eqTjhVYUDEmDcdZCRuaniMKyC7CbM1YAJd4yU0jkSRFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I need this in my C code on the server side. Any link to the `jsonb_each`
for this? Examples I found in a quick search are on the client side in SQL.

I am just confused about the various jsonb types and how to effectively
extract values and convert between them:

There are Jsonb, JsonbValue (plus the associated JsonbPair ) to begin with.
The ` JsonbToCStringWorker ` example that Andrew pointed out uses still
another "JsonbContainer" type.
But the type I get from "PG_GETARG_JSONB_P" is Jsonb. And it doesn't fit
into " JsonbContainer" or the pointer math about "JsonPair" that I found
online.

What I am struggling with adapting some of the iterator code I saw is how
to delete irrelevant code without breaking it. My use case is very
restricted and handles hstore-like jsonb's.
I don't need or want the code to have the ability to descend into nested
objects or handle arrays etc., as they are invalid input in my case.

I thought the pointer math example I found is easier to adapt, but I
couldn't get a valid "JsonbPair" from the input parameter to feed into the
pointer math.

On Tue, Mar 19, 2019 at 9:50 AM Michel Pelletier <pelletier(dot)michel(at)gmail(dot)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(at)tao11(dot)riddles(dot)org(dot)uk>
> wrote:
>
>> >>>>> "T" == T L <tinlyx(at)gmail(dot)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)
>>
>>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michel Pelletier 2019-03-19 19:22:05 Re: printing JsonbPair values of input JSONB on server side?
Previous Message Radoslav Nedyalkov 2019-03-19 16:35:20 subscription broken after upgrade to pg11