388{
389 char *outputstr;
390 text *jsontext;
391
392 check_stack_depth();
393
394
395 Assert(!(key_scalar && is_null));
396
397 if (is_null)
398 {
399 appendStringInfoString(
result,
"null");
400 return;
401 }
402
403 if (key_scalar &&
408 ereport(ERROR,
409 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
410 errmsg("key value must be scalar, not array, composite, or json")));
411
412 switch (tcategory)
413 {
416 break;
419 break;
421 outputstr = DatumGetBool(val) ? "true" : "false";
422 if (key_scalar)
423 escape_json(
result, outputstr);
424 else
425 appendStringInfoString(
result, outputstr);
426 break;
428 outputstr = OidOutputFunctionCall(outfuncoid, val);
429
430
431
432
433
434 if (!key_scalar && IsValidJsonNumber(outputstr, strlen(outputstr)))
435 appendStringInfoString(
result, outputstr);
436 else
437 escape_json(
result, outputstr);
438 pfree(outputstr);
439 break;
441 {
442 char buf[MAXDATELEN + 1];
443
445 appendStringInfo(
result,
"\"%s\"", buf);
446 }
447 break;
449 {
450 char buf[MAXDATELEN + 1];
451
453 appendStringInfo(
result,
"\"%s\"", buf);
454 }
455 break;
457 {
458 char buf[MAXDATELEN + 1];
459
461 appendStringInfo(
result,
"\"%s\"", buf);
462 }
463 break;
465
466 outputstr = OidOutputFunctionCall(outfuncoid, val);
467 appendStringInfoString(
result, outputstr);
468 pfree(outputstr);
469 break;
471
472 jsontext = DatumGetTextPP(OidFunctionCall1(outfuncoid, val));
473 outputstr = text_to_cstring(jsontext);
474 appendStringInfoString(
result, outputstr);
475 pfree(outputstr);
476 pfree(jsontext);
477 break;
478 default:
479 outputstr = OidOutputFunctionCall(outfuncoid, val);
480 escape_json(
result, outputstr);
481 pfree(outputstr);
482 break;
483 }
484}
char result[OUT_DOUBLE_BUFFER_SIZE]
static char * postgis_JsonEncodeDateTime(char *buf, Datum value, Oid typid)
static void composite_to_json(Datum composite, StringInfo result, bool use_line_feeds)
static void array_to_json_internal(Datum array, StringInfo result, bool use_line_feeds)