Re: printing JsonbPair values of input JSONB on server side? - Mailing list pgsql-general

From Andrew Gierth
Subject Re: printing JsonbPair values of input JSONB on server side?
Date
Msg-id 87r2b4x7pg.fsf@news-spur.riddles.org.uk
Whole thread Raw
In response to printing JsonbPair values of input JSONB on server side?  (T L <tinlyx@gmail.com>)
Responses Re: printing JsonbPair values of input JSONB on server side?  (T L <tinlyx@gmail.com>)
List pgsql-general
>>>>> "T" == T L <tinlyx@gmail.com> writes:

 T>     //Problem line!!!
 T>     //            elog(NOTICE, "print_kv_pair(): k = %s, v = %s",
 T>      ptr-> key.val.string.val, numeric_out(ptr->value.val.numeric));

string.val isn't a C string (notice the "not null terminated" comment in
the structure definition), and you can't call numeric_out like that.
Either of those would crash it.

You could use pnstrdup to get a valid C string, and use
DatumGetCString(DirectFunctionCall1(
                  numeric_out,
                  NumericGetDatum(ptr->value.val.numeric)))

to get the numeric value as a C string.

-- 
Andrew (irc:RhodiumToad)


pgsql-general by date:

Previous
From: T L
Date:
Subject: printing JsonbPair values of input JSONB on server side?
Next
From: T L
Date:
Subject: Re: printing JsonbPair values of input JSONB on server side?