PostgreSQL Source Code  git master
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

void _PG_init (void)
 
static PyObject * PLyObject_FromJsonbContainer (JsonbContainer *jsonb)
 
static JsonbValuePLyObject_ToJsonbValue (PyObject *obj, JsonbParseState **jsonb_state, bool is_elem)
 
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 60 of file jsonb_plpython.c.

◆ PLyObject_AsString

#define PLyObject_AsString   (PLyObject_AsString_p)

Definition at line 57 of file jsonb_plpython.c.

◆ PLyUnicode_FromStringAndSize

#define PLyUnicode_FromStringAndSize   (PLyUnicode_FromStringAndSize_p)

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

◆ PLyObject_AsString_t

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

Definition at line 15 of file jsonb_plpython.c.

◆ PLyUnicode_FromStringAndSize_t

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

Definition at line 31 of file jsonb_plpython.c.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 39 of file jsonb_plpython.c.

40 {
41  /* Asserts verify that typedefs above match original declarations */
44  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyObject_AsString",
45  true, NULL);
48  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLyUnicode_FromStringAndSize",
49  true, NULL);
52  load_external_function("$libdir/" PLPYTHON_LIBNAME, "PLy_elog_impl",
53  true, NULL);
54 }
#define AssertVariableIsOfType(varname, typename)
Definition: c.h:974
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:105
#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 476 of file jsonb_plpython.c.

477 {
478  PyObject *result;
479  Jsonb *in = PG_GETARG_JSONB_P(0);
480 
481  /*
482  * Initialize pointer to Decimal constructor. First we try "cdecimal", C
483  * version of decimal library. In case of failure we use slower "decimal"
484  * module.
485  */
486  if (!decimal_constructor)
487  {
488  PyObject *decimal_module = PyImport_ImportModule("cdecimal");
489 
490  if (!decimal_module)
491  {
492  PyErr_Clear();
493  decimal_module = PyImport_ImportModule("decimal");
494  }
495  Assert(decimal_module);
496  decimal_constructor = PyObject_GetAttrString(decimal_module, "Decimal");
497  }
498 
499  result = PLyObject_FromJsonbContainer(&in->root);
500  if (!result)
501  PLy_elog(ERROR, "transformation from jsonb to Python failed");
502 
503  return PointerGetDatum(result);
504 }
#define ERROR
Definition: elog.h:33
#define PG_GETARG_JSONB_P(x)
Definition: jsonb.h:74
#define PLy_elog
static PyObject * decimal_constructor
static PyObject * PLyObject_FromJsonbContainer(JsonbContainer *jsonb)
Assert(fmt[strlen(fmt) - 1] !='\n')
#define PointerGetDatum(X)
Definition: postgres.h:600
Definition: jsonb.h:221
JsonbContainer root
Definition: jsonb.h:223

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

459 {
460  PyObject *obj;
461  JsonbValue *out;
462  JsonbParseState *jsonb_state = NULL;
463 
464  obj = (PyObject *) PG_GETARG_POINTER(0);
465  out = PLyObject_ToJsonbValue(obj, &jsonb_state, true);
467 }
#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:94

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

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

References i, 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 359 of file jsonb_plpython.c.

360 {
361  Numeric num;
362  char *str = PLyObject_AsString(obj);
363 
364  PG_TRY();
365  {
366  Datum numd;
367 
371  Int32GetDatum(-1));
372  num = DatumGetNumeric(numd);
373  }
374  PG_CATCH();
375  {
376  ereport(ERROR,
377  (errcode(ERRCODE_DATATYPE_MISMATCH),
378  errmsg("could not convert value \"%s\" to jsonb", str)));
379  }
380  PG_END_TRY();
381 
382  pfree(str);
383 
384  /*
385  * jsonb doesn't allow NaN or infinity (per JSON specification), so we
386  * have to reject those here explicitly.
387  */
388  if (numeric_is_nan(num))
389  ereport(ERROR,
390  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
391  errmsg("cannot convert NaN to jsonb")));
392  if (numeric_is_inf(num))
393  ereport(ERROR,
394  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
395  errmsg("cannot convert infinity to jsonb")));
396 
397  jbvNum->type = jbvNumeric;
398  jbvNum->val.numeric = num;
399 
400  return jbvNum;
401 }
Datum numeric_in(PG_FUNCTION_ARGS)
Definition: numeric.c:617
bool numeric_is_nan(Numeric num)
Definition: numeric.c:770
bool numeric_is_inf(Numeric num)
Definition: numeric.c:781
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define PG_CATCH()
Definition: elog.h:309
#define ereport(elevel,...)
Definition: elog.h:143
#define DirectFunctionCall3(func, arg1, arg2, arg3)
Definition: fmgr.h:635
@ jbvNumeric
Definition: jsonb.h:238
void pfree(void *pointer)
Definition: mcxt.c:1175
#define DatumGetNumeric(X)
Definition: numeric.h:59
#define CStringGetDatum(X)
Definition: postgres.h:622
uintptr_t Datum
Definition: postgres.h:411
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define Int32GetDatum(X)
Definition: postgres.h:523
#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, generate_unaccent_rules::str, JsonbValue::type, and JsonbValue::val.

Referenced by PLyObject_ToJsonbValue().

◆ PLyObject_FromJsonbContainer()

static PyObject * PLyObject_FromJsonbContainer ( JsonbContainer jsonb)
static

Definition at line 136 of file jsonb_plpython.c.

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

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

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

References DatumGetCString, decimal_constructor, DirectFunctionCall1, elog, ERROR, jbvBinary, jbvBool, jbvNull, jbvNumeric, jbvString, numeric_out(), NumericGetDatum, PLyObject_FromJsonbContainer(), PLyUnicode_FromJsonbValue(), generate_unaccent_rules::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 409 of file jsonb_plpython.c.

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

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

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

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

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

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

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

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

Referenced by _PG_init().

◆ PLyObject_AsString_p

PLyObject_AsString_t PLyObject_AsString_p
static

Definition at line 16 of file jsonb_plpython.c.

Referenced by _PG_init().

◆ PLyUnicode_FromStringAndSize_p

PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p
static

Definition at line 33 of file jsonb_plpython.c.

Referenced by _PG_init().