MCPcopy Create free account
hub / github.com/documentdb/documentdb / bsonaggvalue_out

Function bsonaggvalue_out

pg_documentdb/src/aggregation/bson_aggregates.c:2641–2667  ·  view source on GitHub ↗

* bsonaggvalue_out: Convert BsonAggValue to text output. * Returns the value wrapped as {"": value} with an optional "collation" field. * Uses hex representation by default, or extended JSON when the GUC is set. */

Source from the content-addressed store, hash-verified

2639 * Uses hex representation by default, or extended JSON when the GUC is set.
2640 */
2641Datum
2642bsonaggvalue_out(PG_FUNCTION_ARGS)
2643{
2644 BsonAggValue *state = (BsonAggValue *) PG_GETARG_POINTER(0);
2645
2646 pgbson_writer writer;
2647 PgbsonWriterInit(&writer);
2648 AppendBsonAggValueToWriter(&writer, &state->value);
2649 if (state->collationString != NULL)
2650 {
2651 PgbsonWriterAppendUtf8(&writer, "collation", strlen("collation"),
2652 state->collationString);
2653 }
2654 pgbson *bson = PgbsonWriterGetPgbson(&writer);
2655
2656 const char *outputString = NULL;
2657 if (BsonTextUseJsonRepresentation)
2658 {
2659 outputString = PgbsonToCanonicalExtendedJson(bson);
2660 }
2661 else
2662 {
2663 outputString = PgbsonToHexadecimalString(bson);
2664 }
2665
2666 PG_RETURN_CSTRING(outputString);
2667}
2668
2669
2670/*

Callers

nothing calls this directly

Calls 6

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendUtf8Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85

Tested by

no test coverage detected