* command_insert_bulk handles the insert command invocation through a PostgreSQL procedure and commits after each batch. */
| 178 | * command_insert_bulk handles the insert command invocation through a PostgreSQL procedure and commits after each batch. |
| 179 | */ |
| 180 | Datum |
| 181 | command_insert_bulk(PG_FUNCTION_ARGS) |
| 182 | { |
| 183 | ReportFeatureUsage(FEATURE_COMMAND_INSERT_BULK); |
| 184 | bool isTopLevel = true; |
| 185 | if (IsInTransactionBlock(isTopLevel)) |
| 186 | { |
| 187 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_OPERATIONNOTSUPPORTEDINTRANSACTION), |
| 188 | errmsg("the insert procedure cannot be used in transactions." |
| 189 | " Please use the insert function instead"))); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | /* For results we need a stable memory context across transactions */ |
| 194 | MemoryContext stableContext = fcinfo->flinfo->fn_mcxt; |
| 195 | Datum result = CommandInsertCore(fcinfo, WriteMode_Bulk_Proc, stableContext); |
| 196 | |
| 197 | /* If it's not transactional, pop the active snapshot created during the transaction start */ |
| 198 | if (ActiveSnapshotSet()) |
| 199 | { |
| 200 | Snapshot snapshot = GetActiveSnapshot(); |
| 201 | if (ActivePortal != NULL && ActivePortal->portalSnapshot == snapshot) |
| 202 | { |
| 203 | ActivePortal->portalSnapshot = NULL; |
| 204 | } |
| 205 | |
| 206 | PopActiveSnapshot(); |
| 207 | } |
| 208 | |
| 209 | PG_RETURN_DATUM(result); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | /* |
nothing calls this directly
no test coverage detected