* command_update handles a single update on a collection. */
| 516 | * command_update handles a single update on a collection. |
| 517 | */ |
| 518 | Datum |
| 519 | command_update(PG_FUNCTION_ARGS) |
| 520 | { |
| 521 | if (PG_ARGISNULL(1)) |
| 522 | { |
| 523 | ereport(ERROR, (errmsg("update document cannot be NULL"))); |
| 524 | } |
| 525 | |
| 526 | Datum databaseNameDatum = PG_ARGISNULL(0) ? (Datum) 0 : PG_GETARG_DATUM(0); |
| 527 | pgbson *updateSpec = PG_GETARG_PGBSON(1); |
| 528 | |
| 529 | pgbsonsequence *updateDocs = PG_GETARG_MAYBE_NULL_PGBSON_SEQUENCE(2); |
| 530 | |
| 531 | text *transactionId = NULL; |
| 532 | if (!PG_ARGISNULL(3)) |
| 533 | { |
| 534 | transactionId = PG_GETARG_TEXT_P(3); |
| 535 | } |
| 536 | |
| 537 | ReportFeatureUsage(FEATURE_COMMAND_UPDATE); |
| 538 | |
| 539 | /* fetch TupleDesc for return value, not interested in resultTypeId */ |
| 540 | Oid *resultTypeId = NULL; |
| 541 | TupleDesc resultTupDesc; |
| 542 | TypeFuncClass resultTypeClass = |
| 543 | get_call_result_type(fcinfo, resultTypeId, &resultTupDesc); |
| 544 | |
| 545 | if (resultTypeClass != TYPEFUNC_COMPOSITE) |
| 546 | { |
| 547 | ereport(ERROR, (errmsg("return type must be a row type"))); |
| 548 | } |
| 549 | |
| 550 | HeapTuple resultTuple = PerformUpdateCore(&databaseNameDatum, updateSpec, updateDocs, |
| 551 | transactionId, resultTupDesc, |
| 552 | WriteMode_Txn_Func, CurrentMemoryContext); |
| 553 | PG_RETURN_DATUM(HeapTupleGetDatum(resultTuple)); |
| 554 | } |
| 555 | |
| 556 | |
| 557 | inline static bool |
nothing calls this directly
no test coverage detected