* A wire protocol bulk update on a collection (non-transactional) * this is same as command_update but using procedure */
| 411 | * this is same as command_update but using procedure |
| 412 | */ |
| 413 | Datum |
| 414 | command_update_bulk(PG_FUNCTION_ARGS) |
| 415 | { |
| 416 | if (PG_ARGISNULL(1)) |
| 417 | { |
| 418 | ereport(ERROR, (errmsg("update document cannot be NULL"))); |
| 419 | } |
| 420 | |
| 421 | Datum databaseNameDatum = PG_ARGISNULL(0) ? (Datum) 0 : PG_GETARG_DATUM(0); |
| 422 | pgbson *updateSpec = PG_GETARG_PGBSON(1); |
| 423 | pgbsonsequence *updateDocs = PG_GETARG_MAYBE_NULL_PGBSON_SEQUENCE(2); |
| 424 | |
| 425 | text *transactionId = NULL; |
| 426 | if (!PG_ARGISNULL(3)) |
| 427 | { |
| 428 | transactionId = PG_GETARG_TEXT_P(3); |
| 429 | } |
| 430 | |
| 431 | bool isTopLevel = true; |
| 432 | if (IsInTransactionBlock(isTopLevel)) |
| 433 | { |
| 434 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_OPERATIONNOTSUPPORTEDINTRANSACTION), |
| 435 | errmsg("the bulk update procedure cannot be used in transactions." |
| 436 | " Please use the update function instead"))); |
| 437 | } |
| 438 | |
| 439 | ReportFeatureUsage(FEATURE_COMMAND_UPDATE_BULK); |
| 440 | |
| 441 | /* fetch TupleDesc for return value, not interested in resultTypeId */ |
| 442 | Oid *resultTypeId = NULL; |
| 443 | TupleDesc resultTupDesc; |
| 444 | TypeFuncClass resultTypeClass = |
| 445 | get_call_result_type(fcinfo, resultTypeId, &resultTupDesc); |
| 446 | |
| 447 | if (resultTypeClass != TYPEFUNC_COMPOSITE) |
| 448 | { |
| 449 | ereport(ERROR, (errmsg("return type must be a row type"))); |
| 450 | } |
| 451 | |
| 452 | /* For results we need a stable memory context across transactions */ |
| 453 | MemoryContext stableContext = fcinfo->flinfo->fn_mcxt; |
| 454 | |
| 455 | HeapTuple resultTuple = PerformUpdateCore(&databaseNameDatum, updateSpec, updateDocs, |
| 456 | transactionId, resultTupDesc, |
| 457 | WriteMode_Bulk_Proc, stableContext); |
| 458 | PG_RETURN_DATUM(HeapTupleGetDatum(resultTuple)); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | /* |
nothing calls this directly
no test coverage detected