PostgreSQL Source Code git master
jsonb_plpython.c File Reference
#include "postgres.h"
#include "plpy_elog.h"
#include "plpy_typeio.h"
#include "plpy_util.h"
#include "utils/fmgrprotos.h"
#include "utils/jsonb.h"
#include "utils/numeric.h"
Include dependency graph for jsonb_plpython.c:

Go to the source code of this file.

Macros

#define PLyObject_AsString   (PLyObject_AsString_p)
 
#define PLyUnicode_FromStringAndSize   (PLyUnicode_FromStringAndSize_p)
 
#define PLy_elog   (PLy_elog_impl_p)
 

Typedefs

typedef char *(* PLyObject_AsString_t) (PyObject *plrv)
 
typedef void(* PLy_elog_impl_t) (int elevel, const char *fmt,...)
 
typedef PyObject *(* PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size)
 

Functions

 PG_MODULE_MAGIC_EXT (.name="jsonb_plpython",.version=PG_VERSION)
 
static PyObject * PLyObject_FromJsonbContainer (JsonbContainer *jsonb)
 
static JsonbValuePLyObject_ToJsonbValue (PyObject *obj, JsonbParseState **jsonb_state, bool is_elem)
 
void _PG_init (void)
 
static PyObject * PLyUnicode_FromJsonbValue (JsonbValue *jbv)
 
static void PLyUnicode_ToJsonbValue (PyObject *obj, JsonbValue *jbvElem)
 
static PyObject * PLyObject_FromJsonbValue (JsonbValue *jsonbValue)
 
static JsonbValuePLyMapping_ToJsonbValue (PyObject *obj, JsonbParseState **jsonb_state)
 
static JsonbValuePLySequence_ToJsonbValue (PyObject *obj, JsonbParseState **jsonb_state)
 
static JsonbValuePLyNumber_ToJsonbValue (PyObject *obj, JsonbValue *jbvNum)
 
 PG_FUNCTION_INFO_V1 (plpython_to_jsonb)
 
Datum plpython_to_jsonb (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (jsonb_to_plpython)
 
Datum jsonb_to_plpython (PG_FUNCTION_ARGS)
 

Variables

static PLyObject_AsString_t PLyObject_AsString_p
 
static PLy_elog_impl_t PLy_elog_impl_p
 
static PyObject * decimal_constructor
 
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p
 

Macro Definition Documentation

◆ PLy_elog

#define PLy_elog   (PLy_elog_impl_p)

Definition at line 61 of file jsonb_plpython.c.

◆ PLyObject_AsString

#define PLyObject_AsString   (PLyObject_AsString_p)

Definition at line 58 of file jsonb_plpython.c.

◆ PLyUnicode_FromStringAndSize

#define PLyUnicode_FromStringAndSize   (PLyUnicode_FromStringAndSize_p)

Definition at line 59 of file jsonb_plpython.c.

Typedef Documentation

◆ PLy_elog_impl_t

typedef void(* PLy_elog_impl_t) (int elevel, const char *fmt,...)

Definition at line 19 of file jsonb_plpython.c.

◆ PLyObject_AsString_t

typedef char *(* PLyObject_AsString_t) (PyObject *plrv)

Definition at line 16 of file jsonb_plpython.c.

◆ PLyUnicode_FromStringAndSize_t

typedef PyObject *(* PLyUnicode_FromStringAndSize_t) (const char *s, Py_ssize_t size)

Definition at line 32 of file jsonb_plpython.c.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 40 of file jsonb_plpython.c.

41{
42 /* Asserts verify that typedefs above match original declarations */
45 load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
46 true, NULL);
49 load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
50 true, NULL);
53 load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLy_elog_impl",
54 true, NULL);
55}
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:952
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:95
#define PLyUnicode_FromStringAndSize
static PLy_elog_impl_t PLy_elog_impl_p
PyObject *(* PLyUnicode_FromStringAndSize_t)(const char *s, Py_ssize_t size)
void(* PLy_elog_impl_t)(int elevel, const char *fmt,...)
static PLyObject_AsString_t PLyObject_AsString_p
char *(* PLyObject_AsString_t)(PyObject *plrv)
static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p
#define PLyObject_AsString
void PLy_elog_impl(int elevel, const char *fmt,...)
Definition: plpy_elog.c:43

References AssertVariableIsOfType, load_external_function(), PLy_elog_impl(), PLy_elog_impl_p, PLyObject_AsString, PLyObject_AsString_p, PLyUnicode_FromStringAndSize, and PLyUnicode_FromStringAndSize_p.

◆ jsonb_to_plpython()

Datum jsonb_to_plpython ( PG_FUNCTION_ARGS  )

Definition at line 477 of file jsonb_plpython.c.

478{
479 PyObject *result;
480 Jsonb *in = PG_GETARG_JSONB_P(0);
481
482 /*
483 * Initialize pointer to Decimal constructor. First we try "cdecimal", C
484 * version of decimal library. In case of failure we use slower "decimal"
485 * module.
486 */
488 {
489 PyObject *decimal_module = PyImport_ImportModule("cdecimal");
490
491 if (!decimal_module)
492 {
493 PyErr_Clear();
494 decimal_module = PyImport_ImportModule("decimal");
495 }
496 Assert(decimal_module);
497 decimal_constructor = PyObject_GetAttrString(decimal_module, "Decimal");
498 }
499
500 result = PLyObject_FromJsonbContainer(&in->root);
501 if (!result)
502 PLy_elog(ERROR, "transformation from jsonb to Python failed");
503
504 return PointerGetDatum(result);
505}
#define ERROR
Definition: elog.h:39
Assert(PointerIsAligned(start, uint64))
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:391
#define PLy_elog
static PyObject * decimal_constructor
static PyObject * PLyObject_FromJsonbContainer(JsonbContainer *jsonb)
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327
Definition: jsonb.h:213
JsonbContainer root
Definition: jsonb.h:215

References Assert(), decimal_constructor, ERROR, PG_GETARG_JSONB_P, PLy_elog, PLyObject_FromJsonbContainer(), PointerGetDatum(), and Jsonb::root.

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( jsonb_to_plpython  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( plpython_to_jsonb  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "jsonb_plpython",
version = PG_VERSION 
)

◆ plpython_to_jsonb()

Datum plpython_to_jsonb ( PG_FUNCTION_ARGS  )

Definition at line 459 of file jsonb_plpython.c.

460{
461 PyObject *obj;
462 JsonbValue *out;
463 JsonbParseState *jsonb_state = NULL;
464
465 obj = (PyObject *) PG_GETARG_POINTER(0);
466 out = PLyObject_ToJsonbValue(obj, &jsonb_state, true);
468}
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
static JsonbValue * PLyObject_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state, bool is_elem)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Definition: jsonb_util.c:92

References JsonbValueToJsonb(), PG_GETARG_POINTER, PG_RETURN_POINTER, and PLyObject_ToJsonbValue().

◆ PLyMapping_ToJsonbValue()

static JsonbValue * PLyMapping_ToJsonbValue ( PyObject *  obj,
JsonbParseState **  jsonb_state 
)
static

Definition at line 265 of file jsonb_plpython.c.

266{
267 Py_ssize_t pcount;
268 PyObject *volatile items;
269 JsonbValue *volatile out;
270
271 pcount = PyMapping_Size(obj);
272 items = PyMapping_Items(obj);
273
274 PG_TRY();
275 {
276 Py_ssize_t i;
277
278 pushJsonbValue(jsonb_state, WJB_BEGIN_OBJECT, NULL);
279
280 for (i = 0; i < pcount; i++)
281 {
282 JsonbValue jbvKey;
283 PyObject *item = PyList_GetItem(items, i);
284 PyObject *key = PyTuple_GetItem(item, 0);
285 PyObject *value = PyTuple_GetItem(item, 1);
286
287 /* Python dictionary can have None as key */
288 if (key == Py_None)
289 {
290 jbvKey.type = jbvString;
291 jbvKey.val.string.len = 0;
292 jbvKey.val.string.val = "";
293 }
294 else
295 {
296 /* All others types of keys we serialize to string */
298 }
299
300 (void) pushJsonbValue(jsonb_state, WJB_KEY, &jbvKey);
301 (void) PLyObject_ToJsonbValue(value, jsonb_state, false);
302 }
303
304 out = pushJsonbValue(jsonb_state, WJB_END_OBJECT, NULL);
305 }
306 PG_FINALLY();
307 {
308 Py_DECREF(items);
309 }
310 PG_END_TRY();
311
312 return out;
313}
#define PG_TRY(...)
Definition: elog.h:371
#define PG_END_TRY(...)
Definition: elog.h:396
#define PG_FINALLY(...)
Definition: elog.h:388
static struct @165 value
int i
Definition: isn.c:77
@ jbvString
Definition: jsonb.h:229
@ WJB_KEY
Definition: jsonb.h:23
@ WJB_END_OBJECT
Definition: jsonb.h:29
@ WJB_BEGIN_OBJECT
Definition: jsonb.h:28
static void PLyUnicode_ToJsonbValue(PyObject *obj, JsonbValue *jbvElem)
JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)
Definition: jsonb_util.c:573
enum jbvType type
Definition: jsonb.h:255
char * val
Definition: jsonb.h:264
static ItemArray items
Definition: test_tidstore.c:48

References i, items, jbvString, sort-test::key, PG_END_TRY, PG_FINALLY, PG_TRY, PLyObject_ToJsonbValue(), PLyUnicode_ToJsonbValue(), pushJsonbValue(), JsonbValue::type, JsonbValue::val, value, WJB_BEGIN_OBJECT, WJB_END_OBJECT, and WJB_KEY.

Referenced by PLyObject_ToJsonbValue().

◆ PLyNumber_ToJsonbValue()

static JsonbValue * PLyNumber_ToJsonbValue ( PyObject *  obj,
JsonbValue jbvNum 
)
static

Definition at line 360 of file jsonb_plpython.c.

361{
362 Numeric num;
363 char *str = PLyObject_AsString(obj);
364
365 PG_TRY();
366 {
367 Datum numd;
368
372 Int32GetDatum(-1));
373 num = DatumGetNumeric(numd);
374 }
375 PG_CATCH();
376 {
378 (errcode(ERRCODE_DATATYPE_MISMATCH),
379 errmsg("could not convert value \"%s\" to jsonb", str)));
380 }
381 PG_END_TRY();
382
383 pfree(str);
384
385 /*
386 * jsonb doesn't allow NaN or infinity (per JSON specification), so we
387 * have to reject those here explicitly.
388 */
389 if (numeric_is_nan(num))
391 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
392 errmsg("cannot convert NaN to jsonb")));
393 if (numeric_is_inf(num))
395 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
396 errmsg("cannot convert infinity to jsonb")));
397
398 jbvNum->type = jbvNumeric;
399 jbvNum->val.numeric = num;
400
401 return jbvNum;
402}
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:637
bool numeric_is_nan(Numeric num)
Definition: numeric.c:851
bool numeric_is_inf(Numeric num)
Definition: numeric.c:862
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define PG_CATCH(...)
Definition: elog.h:381
#define ereport(elevel,...)
Definition: elog.h:149
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:686
const char * str
@ jbvNumeric
Definition: jsonb.h:230
void pfree(void *pointer)
Definition: mcxt.c:2152
static Numeric DatumGetNumeric(Datum X)
Definition: numeric.h:61
uintptr_t Datum
Definition: postgres.h:69
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:355
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:217
#define InvalidOid
Definition: postgres_ext.h:35

References CStringGetDatum(), DatumGetNumeric(), DirectFunctionCall3, ereport, errcode(), errmsg(), ERROR, Int32GetDatum(), InvalidOid, jbvNumeric, numeric_in(), numeric_is_inf(), numeric_is_nan(), ObjectIdGetDatum(), pfree(), PG_CATCH, PG_END_TRY, PG_TRY, PLyObject_AsString, str, JsonbValue::type, and JsonbValue::val.

Referenced by PLyObject_ToJsonbValue().

◆ PLyObject_FromJsonbContainer()

static PyObject * PLyObject_FromJsonbContainer ( JsonbContainer jsonb)
static

Definition at line 137 of file jsonb_plpython.c.

138{
140 JsonbValue v;
141 JsonbIterator *it;
142 PyObject *result;
143
144 it = JsonbIteratorInit(jsonb);
145 r = JsonbIteratorNext(&it, &v, true);
146
147 switch (r)
148 {
149 case WJB_BEGIN_ARRAY:
150 if (v.val.array.rawScalar)
151 {
152 JsonbValue tmp;
153
154 if ((r = JsonbIteratorNext(&it, &v, true)) != WJB_ELEM ||
155 (r = JsonbIteratorNext(&it, &tmp, true)) != WJB_END_ARRAY ||
156 (r = JsonbIteratorNext(&it, &tmp, true)) != WJB_DONE)
157 elog(ERROR, "unexpected jsonb token: %d", r);
158
159 result = PLyObject_FromJsonbValue(&v);
160 }
161 else
162 {
163 PyObject *volatile elem = NULL;
164
165 result = PyList_New(0);
166 if (!result)
167 return NULL;
168
169 PG_TRY();
170 {
171 while ((r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE)
172 {
173 if (r != WJB_ELEM)
174 continue;
175
176 elem = PLyObject_FromJsonbValue(&v);
177
178 PyList_Append(result, elem);
179 Py_XDECREF(elem);
180 elem = NULL;
181 }
182 }
183 PG_CATCH();
184 {
185 Py_XDECREF(elem);
186 Py_XDECREF(result);
187 PG_RE_THROW();
188 }
189 PG_END_TRY();
190 }
191 break;
192
193 case WJB_BEGIN_OBJECT:
194 {
195 PyObject *volatile result_v = PyDict_New();
196 PyObject *volatile key = NULL;
197 PyObject *volatile val = NULL;
198
199 if (!result_v)
200 return NULL;
201
202 PG_TRY();
203 {
204 while ((r = JsonbIteratorNext(&it, &v, true)) != WJB_DONE)
205 {
206 if (r != WJB_KEY)
207 continue;
208
210 if (!key)
211 {
212 Py_XDECREF(result_v);
213 result_v = NULL;
214 break;
215 }
216
217 if ((r = JsonbIteratorNext(&it, &v, true)) != WJB_VALUE)
218 elog(ERROR, "unexpected jsonb token: %d", r);
219
221 if (!val)
222 {
223 Py_XDECREF(key);
224 key = NULL;
225 Py_XDECREF(result_v);
226 result_v = NULL;
227 break;
228 }
229
230 PyDict_SetItem(result_v, key, val);
231
232 Py_XDECREF(key);
233 key = NULL;
234 Py_XDECREF(val);
235 val = NULL;
236 }
237 }
238 PG_CATCH();
239 {
240 Py_XDECREF(result_v);
241 Py_XDECREF(key);
242 Py_XDECREF(val);
243 PG_RE_THROW();
244 }
245 PG_END_TRY();
246
247 result = result_v;
248 }
249 break;
250
251 default:
252 elog(ERROR, "unexpected jsonb token: %d", r);
253 return NULL;
254 }
255
256 return result;
257}
#define PG_RE_THROW()
Definition: elog.h:404
#define elog(elevel,...)
Definition: elog.h:225
long val
Definition: informix.c:689
JsonbIteratorToken
Definition: jsonb.h:21
@ WJB_DONE
Definition: jsonb.h:22
@ WJB_END_ARRAY
Definition: jsonb.h:27
@ WJB_VALUE
Definition: jsonb.h:24
@ WJB_ELEM
Definition: jsonb.h:25
@ WJB_BEGIN_ARRAY
Definition: jsonb.h:26
static PyObject * PLyObject_FromJsonbValue(JsonbValue *jsonbValue)
static PyObject * PLyUnicode_FromJsonbValue(JsonbValue *jbv)
JsonbIterator * JsonbIteratorInit(JsonbContainer *container)
Definition: jsonb_util.c:824
JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)
Definition: jsonb_util.c:860

References elog, ERROR, JsonbIteratorInit(), JsonbIteratorNext(), sort-test::key, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PLyObject_FromJsonbValue(), PLyUnicode_FromJsonbValue(), JsonbValue::val, val, WJB_BEGIN_ARRAY, WJB_BEGIN_OBJECT, WJB_DONE, WJB_ELEM, WJB_END_ARRAY, WJB_KEY, and WJB_VALUE.

Referenced by jsonb_to_plpython(), and PLyObject_FromJsonbValue().

◆ PLyObject_FromJsonbValue()

static PyObject * PLyObject_FromJsonbValue ( JsonbValue jsonbValue)
static

Definition at line 95 of file jsonb_plpython.c.

96{
97 switch (jsonbValue->type)
98 {
99 case jbvNull:
100 Py_RETURN_NONE;
101
102 case jbvBinary:
103 return PLyObject_FromJsonbContainer(jsonbValue->val.binary.data);
104
105 case jbvNumeric:
106 {
107 Datum num;
108 char *str;
109
110 num = NumericGetDatum(jsonbValue->val.numeric);
112
113 return PyObject_CallFunction(decimal_constructor, "s", str);
114 }
115
116 case jbvString:
117 return PLyUnicode_FromJsonbValue(jsonbValue);
118
119 case jbvBool:
120 if (jsonbValue->val.boolean)
121 Py_RETURN_TRUE;
122 else
123 Py_RETURN_FALSE;
124
125 default:
126 elog(ERROR, "unexpected jsonb value type: %d", jsonbValue->type);
127 return NULL;
128 }
129}
Datum numeric_out(PG_FUNCTION_ARGS)
Definition: numeric.c:816
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:682
@ jbvBool
Definition: jsonb.h:231
@ jbvBinary
Definition: jsonb.h:236
@ jbvNull
Definition: jsonb.h:228
static Datum NumericGetDatum(Numeric X)
Definition: numeric.h:73
static char * DatumGetCString(Datum X)
Definition: postgres.h:340

References DatumGetCString(), decimal_constructor, DirectFunctionCall1, elog, ERROR, jbvBinary, jbvBool, jbvNull, jbvNumeric, jbvString, numeric_out(), NumericGetDatum(), PLyObject_FromJsonbContainer(), PLyUnicode_FromJsonbValue(), str, JsonbValue::type, and JsonbValue::val.

Referenced by PLyObject_FromJsonbContainer().

◆ PLyObject_ToJsonbValue()

static JsonbValue * PLyObject_ToJsonbValue ( PyObject *  obj,
JsonbParseState **  jsonb_state,
bool  is_elem 
)
static

Definition at line 410 of file jsonb_plpython.c.

411{
412 JsonbValue *out;
413
414 if (!PyUnicode_Check(obj))
415 {
416 if (PySequence_Check(obj))
417 return PLySequence_ToJsonbValue(obj, jsonb_state);
418 else if (PyMapping_Check(obj))
419 return PLyMapping_ToJsonbValue(obj, jsonb_state);
420 }
421
422 out = palloc(sizeof(JsonbValue));
423
424 if (obj == Py_None)
425 out->type = jbvNull;
426 else if (PyUnicode_Check(obj))
427 PLyUnicode_ToJsonbValue(obj, out);
428
429 /*
430 * PyNumber_Check() returns true for booleans, so boolean check should
431 * come first.
432 */
433 else if (PyBool_Check(obj))
434 {
435 out->type = jbvBool;
436 out->val.boolean = (obj == Py_True);
437 }
438 else if (PyNumber_Check(obj))
439 out = PLyNumber_ToJsonbValue(obj, out);
440 else
442 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
443 errmsg("Python type \"%s\" cannot be transformed to jsonb",
444 PLyObject_AsString((PyObject *) obj->ob_type))));
445
446 /* Push result into 'jsonb_state' unless it is raw scalar value. */
447 return (*jsonb_state ?
448 pushJsonbValue(jsonb_state, is_elem ? WJB_ELEM : WJB_VALUE, out) :
449 out);
450}
static JsonbValue * PLyMapping_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
static JsonbValue * PLyNumber_ToJsonbValue(PyObject *obj, JsonbValue *jbvNum)
static JsonbValue * PLySequence_ToJsonbValue(PyObject *obj, JsonbParseState **jsonb_state)
void * palloc(Size size)
Definition: mcxt.c:1945

References ereport, errcode(), errmsg(), ERROR, jbvBool, jbvNull, palloc(), PLyMapping_ToJsonbValue(), PLyNumber_ToJsonbValue(), PLyObject_AsString, PLySequence_ToJsonbValue(), PLyUnicode_ToJsonbValue(), pushJsonbValue(), JsonbValue::type, JsonbValue::val, WJB_ELEM, and WJB_VALUE.

Referenced by plpython_to_jsonb(), PLyMapping_ToJsonbValue(), and PLySequence_ToJsonbValue().

◆ PLySequence_ToJsonbValue()

static JsonbValue * PLySequence_ToJsonbValue ( PyObject *  obj,
JsonbParseState **  jsonb_state 
)
static

Definition at line 322 of file jsonb_plpython.c.

323{
324 Py_ssize_t i;
325 Py_ssize_t pcount;
326 PyObject *volatile value = NULL;
327
328 pcount = PySequence_Size(obj);
329
330 pushJsonbValue(jsonb_state, WJB_BEGIN_ARRAY, NULL);
331
332 PG_TRY();
333 {
334 for (i = 0; i < pcount; i++)
335 {
336 value = PySequence_GetItem(obj, i);
337 Assert(value);
338
339 (void) PLyObject_ToJsonbValue(value, jsonb_state, true);
340 Py_XDECREF(value);
341 value = NULL;
342 }
343 }
344 PG_CATCH();
345 {
346 Py_XDECREF(value);
347 PG_RE_THROW();
348 }
349 PG_END_TRY();
350
351 return pushJsonbValue(jsonb_state, WJB_END_ARRAY, NULL);
352}

References Assert(), i, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PLyObject_ToJsonbValue(), pushJsonbValue(), value, WJB_BEGIN_ARRAY, and WJB_END_ARRAY.

Referenced by PLyObject_ToJsonbValue().

◆ PLyUnicode_FromJsonbValue()

static PyObject * PLyUnicode_FromJsonbValue ( JsonbValue jbv)
static

Definition at line 69 of file jsonb_plpython.c.

70{
71 Assert(jbv->type == jbvString);
72
73 return PLyUnicode_FromStringAndSize(jbv->val.string.val, jbv->val.string.len);
74}

References Assert(), jbvString, PLyUnicode_FromStringAndSize, JsonbValue::type, and JsonbValue::val.

Referenced by PLyObject_FromJsonbContainer(), and PLyObject_FromJsonbValue().

◆ PLyUnicode_ToJsonbValue()

static void PLyUnicode_ToJsonbValue ( PyObject *  obj,
JsonbValue jbvElem 
)
static

Definition at line 82 of file jsonb_plpython.c.

83{
84 jbvElem->type = jbvString;
85 jbvElem->val.string.val = PLyObject_AsString(obj);
86 jbvElem->val.string.len = strlen(jbvElem->val.string.val);
87}

References jbvString, PLyObject_AsString, JsonbValue::type, and JsonbValue::val.

Referenced by PLyMapping_ToJsonbValue(), and PLyObject_ToJsonbValue().

Variable Documentation

◆ decimal_constructor

PyObject* decimal_constructor
static

◆ PLy_elog_impl_p

PLy_elog_impl_t PLy_elog_impl_p
static

Definition at line 20 of file jsonb_plpython.c.

Referenced by _PG_init().

◆ PLyObject_AsString_p

PLyObject_AsString_t PLyObject_AsString_p
static

Definition at line 17 of file jsonb_plpython.c.

Referenced by _PG_init().

◆ PLyUnicode_FromStringAndSize_p

PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p
static

Definition at line 34 of file jsonb_plpython.c.

Referenced by _PG_init().