PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
jsonb_plpython.c File Reference
#include "postgres.h"
#include "plpy_elog.h"
#include "plpy_typeio.h"
#include "plpython.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

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

 PG_MODULE_MAGIC
 
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 58 of file jsonb_plpython.c.

◆ PLyObject_AsString

#define PLyObject_AsString   (PLyObject_AsString_p)

Definition at line 55 of file jsonb_plpython.c.

◆ PLyUnicode_FromStringAndSize

#define PLyUnicode_FromStringAndSize   (PLyUnicode_FromStringAndSize_p)

Definition at line 56 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 16 of file jsonb_plpython.c.

◆ PLyObject_AsString_t

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

Definition at line 13 of file jsonb_plpython.c.

◆ PLyUnicode_FromStringAndSize_t

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

Definition at line 29 of file jsonb_plpython.c.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 37 of file jsonb_plpython.c.

38 {
39  /* Asserts verify that typedefs above match original declarations */
42  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
43  true, NULL);
46  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
47  true, NULL);
50  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLy_elog_impl",
51  true, NULL);
52 }
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:960
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
char *(* PLyObject_AsString_t)(PyObject *plrv)
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
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 474 of file jsonb_plpython.c.

475 {
476  PyObject *result;
477  Jsonb *in = PG_GETARG_JSONB_P(0);
478 
479  /*
480  * Initialize pointer to Decimal constructor. First we try "cdecimal", C
481  * version of decimal library. In case of failure we use slower "decimal"
482  * module.
483  */
484  if (!decimal_constructor)
485  {
486  PyObject *decimal_module = PyImport_ImportModule("cdecimal");
487 
488  if (!decimal_module)
489  {
490  PyErr_Clear();
491  decimal_module = PyImport_ImportModule("decimal");
492  }
493  Assert(decimal_module);
494  decimal_constructor = PyObject_GetAttrString(decimal_module, "Decimal");
495  }
496 
497  result = PLyObject_FromJsonbContainer(&in->root);
498  if (!result)
499  PLy_elog(ERROR, "transformation from jsonb to Python failed");
500 
501  return PointerGetDatum(result);
502 }
#define Assert(condition)
Definition: c.h:837
#define ERROR
Definition: elog.h:39
#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:322
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  )

◆ plpython_to_jsonb()

Datum plpython_to_jsonb ( PG_FUNCTION_ARGS  )

Definition at line 456 of file jsonb_plpython.c.

457 {
458  PyObject *obj;
459  JsonbValue *out;
460  JsonbParseState *jsonb_state = NULL;
461 
462  obj = (PyObject *) PG_GETARG_POINTER(0);
463  out = PLyObject_ToJsonbValue(obj, &jsonb_state, true);
465 }
#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 262 of file jsonb_plpython.c.

263 {
264  Py_ssize_t pcount;
265  PyObject *volatile items;
266  JsonbValue *volatile out;
267 
268  pcount = PyMapping_Size(obj);
269  items = PyMapping_Items(obj);
270 
271  PG_TRY();
272  {
273  Py_ssize_t i;
274 
275  pushJsonbValue(jsonb_state, WJB_BEGIN_OBJECT, NULL);
276 
277  for (i = 0; i < pcount; i++)
278  {
279  JsonbValue jbvKey;
280  PyObject *item = PyList_GetItem(items, i);
281  PyObject *key = PyTuple_GetItem(item, 0);
282  PyObject *value = PyTuple_GetItem(item, 1);
283 
284  /* Python dictionary can have None as key */
285  if (key == Py_None)
286  {
287  jbvKey.type = jbvString;
288  jbvKey.val.string.len = 0;
289  jbvKey.val.string.val = "";
290  }
291  else
292  {
293  /* All others types of keys we serialize to string */
294  PLyUnicode_ToJsonbValue(key, &jbvKey);
295  }
296 
297  (void) pushJsonbValue(jsonb_state, WJB_KEY, &jbvKey);
298  (void) PLyObject_ToJsonbValue(value, jsonb_state, false);
299  }
300 
301  out = pushJsonbValue(jsonb_state, WJB_END_OBJECT, NULL);
302  }
303  PG_FINALLY();
304  {
305  Py_DECREF(items);
306  }
307  PG_END_TRY();
308 
309  return out;
310 }
#define PG_TRY(...)
Definition: elog.h:371
#define PG_END_TRY(...)
Definition: elog.h:396
#define PG_FINALLY(...)
Definition: elog.h:388
static struct @160 value
int i
Definition: isn.c:72
@ 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:566
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 357 of file jsonb_plpython.c.

358 {
359  Numeric num;
360  char *str = PLyObject_AsString(obj);
361 
362  PG_TRY();
363  {
364  Datum numd;
365 
369  Int32GetDatum(-1));
370  num = DatumGetNumeric(numd);
371  }
372  PG_CATCH();
373  {
374  ereport(ERROR,
375  (errcode(ERRCODE_DATATYPE_MISMATCH),
376  errmsg("could not convert value \"%s\" to jsonb", str)));
377  }
378  PG_END_TRY();
379 
380  pfree(str);
381 
382  /*
383  * jsonb doesn't allow NaN or infinity (per JSON specification), so we
384  * have to reject those here explicitly.
385  */
386  if (numeric_is_nan(num))
387  ereport(ERROR,
388  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
389  errmsg("cannot convert NaN to jsonb")));
390  if (numeric_is_inf(num))
391  ereport(ERROR,
392  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
393  errmsg("cannot convert infinity to jsonb")));
394 
395  jbvNum->type = jbvNumeric;
396  jbvNum->val.numeric = num;
397 
398  return jbvNum;
399 }
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:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define PG_CATCH(...)
Definition: elog.h:381
#define ereport(elevel,...)
Definition: elog.h:149
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:645
const char * str
@ jbvNumeric
Definition: jsonb.h:230
void pfree(void *pointer)
Definition: mcxt.c:1521
static Numeric DatumGetNumeric(Datum X)
Definition: numeric.h:61
uintptr_t Datum
Definition: postgres.h:64
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
#define InvalidOid
Definition: postgres_ext.h:36

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 134 of file jsonb_plpython.c.

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

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 92 of file jsonb_plpython.c.

93 {
94  switch (jsonbValue->type)
95  {
96  case jbvNull:
97  Py_RETURN_NONE;
98 
99  case jbvBinary:
100  return PLyObject_FromJsonbContainer(jsonbValue->val.binary.data);
101 
102  case jbvNumeric:
103  {
104  Datum num;
105  char *str;
106 
107  num = NumericGetDatum(jsonbValue->val.numeric);
109 
110  return PyObject_CallFunction(decimal_constructor, "s", str);
111  }
112 
113  case jbvString:
114  return PLyUnicode_FromJsonbValue(jsonbValue);
115 
116  case jbvBool:
117  if (jsonbValue->val.boolean)
118  Py_RETURN_TRUE;
119  else
120  Py_RETURN_FALSE;
121 
122  default:
123  elog(ERROR, "unexpected jsonb value type: %d", jsonbValue->type);
124  return NULL;
125  }
126 }
Datum numeric_out(PG_FUNCTION_ARGS)
Definition: numeric.c:816
#define DirectFunctionCall1(func, arg1)
Definition: fmgr.h:641
@ 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:335

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 407 of file jsonb_plpython.c.

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

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 319 of file jsonb_plpython.c.

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

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 66 of file jsonb_plpython.c.

67 {
68  Assert(jbv->type == jbvString);
69 
70  return PLyUnicode_FromStringAndSize(jbv->val.string.val, jbv->val.string.len);
71 }

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 79 of file jsonb_plpython.c.

80 {
81  jbvElem->type = jbvString;
82  jbvElem->val.string.val = PLyObject_AsString(obj);
83  jbvElem->val.string.len = strlen(jbvElem->val.string.val);
84 }

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

Referenced by PLyMapping_ToJsonbValue(), and PLyObject_ToJsonbValue().

Variable Documentation

◆ decimal_constructor

PyObject* decimal_constructor
static

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 10 of file jsonb_plpython.c.

◆ PLy_elog_impl_p

PLy_elog_impl_t PLy_elog_impl_p
static

Definition at line 17 of file jsonb_plpython.c.

Referenced by _PG_init().

◆ PLyObject_AsString_p

PLyObject_AsString_t PLyObject_AsString_p
static

Definition at line 14 of file jsonb_plpython.c.

Referenced by _PG_init().

◆ PLyUnicode_FromStringAndSize_p

PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p
static

Definition at line 31 of file jsonb_plpython.c.

Referenced by _PG_init().