PostgreSQL Source Code: contrib/jsonb_plpython/jsonb_plpython.c Source File (original) (raw)

2

6#include "utils/fmgrprotos.h"

9

11 .name = "jsonb_plpython",

13);

14

15

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

18

21

22

23

24

25

27

31

32typedef PyObject *(*PLyUnicode_FromStringAndSize_t)

35

36

40

41

42

43

44

45void

58

59

60#define PLyObject_AsString (PLyObject_AsString_p)

61#define PLyUnicode_FromStringAndSize (PLyUnicode_FromStringAndSize_p)

62#undef PLy_elog

63#define PLy_elog (PLy_elog_impl_p)

64

65

66

67

68

69

77

78

79

80

81

82

83static void

90

91

92

93

94

95

98{

100 {

103

106

108 {

110 char *str;

111

114

116 }

117

120

124 else

126

127 default:

130 }

131}

132

133

134

135

136

137

140{

145

148

149 switch (r)

150 {

152 if (v.val.array.rawScalar)

153 {

155

159 elog(ERROR, "unexpected jsonb token: %d", r);

160

162 }

163 else

164 {

166

168 if (!result)

170

172 {

174 {

176 continue;

177

179

183 }

184 }

186 {

190 }

192 }

193 break;

194

196 {

200

203

205 {

207 {

209 continue;

210

212 if (!key)

213 {

216 break;

217 }

218

220 elog(ERROR, "unexpected jsonb token: %d", r);

221

223 if (val)

224 {

229 break;

230 }

231

233

238 }

239 }

241 {

246 }

248

250 }

251 break;

252

253 default:

254 elog(ERROR, "unexpected jsonb token: %d", r);

256 }

257

258 return result;

259}

260

261

262

263

264

265

266static void

268{

271

274

276 {

278

280

282 {

287

288

290 {

292 jbvKey.val.string.len = 0;

293 jbvKey.val.string.val = "";

294 }

295 else

296 {

297

299 }

300

303 }

304

306 }

308 {

310 }

312}

313

314

315

316

317

318

319

320static void

322{

326

328

330

332 {

334 {

337

341 }

342 }

344 {

347 }

349

351}

352

353

354

355

356

357

360{

363

365 {

367

373 }

375 {

378 errmsg("could not convert value \"%s\" to jsonb", str)));

379 }

381

383

384

385

386

387

391 errmsg("cannot convert NaN to jsonb")));

395 errmsg("cannot convert infinity to jsonb")));

396

398 jbvNum->val.numeric = num;

399

401}

402

403

404

405

406

407

408static void

410{

412

414 {

416 {

418 return;

419 }

421 {

423 return;

424 }

425 }

426

428

433

434

435

436

437

439 {

442 }

445 else

448 errmsg("Python type \"%s\" cannot be transformed to jsonb",

450

452 {

453

455 }

456 else

457 {

458

459

460

461

462

464 }

465}

466

467

468

469

470

471

482

483

484

485

486

487

491{

494

495

496

497

498

499

501 {

503

505 {

508 }

511 }

512

514 if (!result)

515 PLy_elog(ERROR, "transformation from jsonb to Python failed");

516

518}

Datum numeric_out(PG_FUNCTION_ARGS)

Datum numeric_in(PG_FUNCTION_ARGS)

bool numeric_is_nan(Numeric num)

bool numeric_is_inf(Numeric num)

#define Assert(condition)

#define StaticAssertVariableIsOfType(varname, typename)

void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)

int errcode(int sqlerrcode)

#define ereport(elevel,...)

#define palloc_object(type)

#define PG_GETARG_POINTER(n)

#define PG_MODULE_MAGIC_EXT(...)

#define DirectFunctionCall1(func, arg1)

#define PG_FUNCTION_INFO_V1(funcname)

#define DirectFunctionCall3(func, arg1, arg2, arg3)

#define PG_RETURN_POINTER(x)

#define PG_GETARG_JSONB_P(x)

static void PLyMapping_ToJsonbValue(PyObject *obj, JsonbInState *jsonb_state)

#define PLyUnicode_FromStringAndSize

static void PLyObject_ToJsonbValue(PyObject *obj, JsonbInState *jsonb_state, bool is_elem)

static PLy_elog_impl_t PLy_elog_impl_p

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

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

Datum plpython_to_jsonb(PG_FUNCTION_ARGS)

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

static PyObject * PLyObject_FromJsonbValue(JsonbValue *jsonbValue)

static PLyObject_AsString_t PLyObject_AsString_p

StaticAssertVariableIsOfType & PLy_elog_impl

static void PLySequence_ToJsonbValue(PyObject *obj, JsonbInState *jsonb_state)

char *(* PLyObject_AsString_t)(PyObject *plrv)

static PyObject * decimal_constructor

Datum jsonb_to_plpython(PG_FUNCTION_ARGS)

static PLyUnicode_FromStringAndSize_t PLyUnicode_FromStringAndSize_p

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

static PyObject * PLyObject_FromJsonbContainer(JsonbContainer *jsonb)

#define PLyObject_AsString

static PyObject * PLyUnicode_FromJsonbValue(JsonbValue *jbv)

void pushJsonbValue(JsonbInState *pstate, JsonbIteratorToken seq, JsonbValue *jbval)

JsonbIterator * JsonbIteratorInit(JsonbContainer *container)

JsonbIteratorToken JsonbIteratorNext(JsonbIterator **it, JsonbValue *val, bool skipNested)

Jsonb * JsonbValueToJsonb(JsonbValue *val)

void pfree(void *pointer)

static Numeric DatumGetNumeric(Datum X)

static Datum NumericGetDatum(Numeric X)

static Datum PointerGetDatum(const void *X)

static Datum ObjectIdGetDatum(Oid X)

static char * DatumGetCString(Datum X)

static Datum CStringGetDatum(const char *X)

static Datum Int32GetDatum(int32 X)