From: | Michel Pelletier <pelletier(dot)michel(at)gmail(dot)com> |
---|---|
To: | T L <tinlyx(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 19:22:05 |
Message-ID: | CACxu=vLCUX8Wq3gkNo+YF_VATNy2MU6pimEXB52yOEAO2MK5Tg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
jsonb_each is a wrapper around each_worker_jsonb. It produces a row for
every key/value pair in an object.
https://doxygen.postgresql.org/jsonfuncs_8c.html#a7511a3aa3918eb956f3f4211d07bdbb0
the iteration is:
while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
On Tue, Mar 19, 2019 at 11:20 AM T L <tinlyx(at)gmail(dot)com> wrote:
> 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)
>>>
>>>
From | Date | Subject | |
---|---|---|---|
Next Message | Peter J. Holzer | 2019-03-19 19:37:27 | Re: Performance of ByteA: ascii vs binary |
Previous Message | T L | 2019-03-19 18:20:04 | Re: printing JsonbPair values of input JSONB on server side? |