| 478 | */ |
| 479 | PG_FUNCTION_INFO_V1(jsonb_to_plpython); |
| 480 | Datum |
| 481 | jsonb_to_plpython(PG_FUNCTION_ARGS) |
| 482 | { |
| 483 | PyObject *result; |
| 484 | Jsonb *in = PG_GETARG_JSONB_P(0); |
| 485 | |
| 486 | /* |
| 487 | * Initialize pointer to Decimal constructor. First we try "cdecimal", C |
| 488 | * version of decimal library. In case of failure we use slower "decimal" |
| 489 | * module. |
| 490 | */ |
| 491 | if (!decimal_constructor) |
| 492 | { |
| 493 | PyObject *decimal_module = PyImport_ImportModule("cdecimal"); |
| 494 | |
| 495 | if (!decimal_module) |
| 496 | { |
| 497 | PyErr_Clear(); |
| 498 | decimal_module = PyImport_ImportModule("decimal"); |
| 499 | } |
| 500 | Assert(decimal_module); |
| 501 | decimal_constructor = PyObject_GetAttrString(decimal_module, "Decimal"); |
| 502 | } |
| 503 | |
| 504 | result = PLyObject_FromJsonbContainer(&in->root); |
| 505 | if (!result) |
| 506 | PLy_elog(ERROR, "transformation from jsonb to Python failed"); |
| 507 | |
| 508 | return PointerGetDatum(result); |
| 509 | } |
nothing calls this directly
no test coverage detected