* 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. */
| 2639 | * Uses hex representation by default, or extended JSON when the GUC is set. |
| 2640 | */ |
| 2641 | Datum |
| 2642 | bsonaggvalue_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 | /* |
nothing calls this directly
no test coverage detected