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

Function RunInsertQuery

pg_documentdb/src/commands/insert.c:1563–1602  ·  view source on GitHub ↗

* Executes the Insert query and returns the total count of processed results. */

Source from the content-addressed store, hash-verified

1561 * Executes the Insert query and returns the total count of processed results.
1562 */
1563static uint64_t
1564RunInsertQuery(Query *insertQuery, ParamListInfo paramListInfo)
1565{
1566 uint64_t numRowsProcessed = 0;
1567
1568 int cursorOptions = CURSOR_OPT_NO_SCROLL | CURSOR_OPT_BINARY;
1569 Portal queryPortal = CreateNewPortal();
1570 queryPortal->visible = false;
1571 queryPortal->cursorOptions = cursorOptions;
1572
1573 PlannedStmt *queryPlan = pg_plan_query(insertQuery, NULL, cursorOptions,
1574 paramListInfo);
1575
1576 /* Set the plan in the cursor for this iteration */
1577 PortalDefineQuery(queryPortal, NULL, "",
1578 CMDTAG_SELECT,
1579 list_make1(queryPlan),
1580 NULL);
1581
1582 /* Trigger execution (Start the ExecEngine etc.) */
1583 PortalStart(queryPortal, paramListInfo, 0, GetActiveSnapshot());
1584
1585 if (SPI_connect() != SPI_OK_CONNECT)
1586 {
1587 ereport(ERROR, (errmsg("could not connect to SPI manager")));
1588 }
1589
1590 /* run through everything but load no results. */
1591 SPI_cursor_move(queryPortal, true, FETCH_ALL);
1592
1593 numRowsProcessed = SPI_processed;
1594 SPI_cursor_close(queryPortal);
1595
1596 if (SPI_finish() != SPI_OK_FINISH)
1597 {
1598 ereport(ERROR, (errmsg("could not complete SPI query")));
1599 }
1600
1601 return numRowsProcessed;
1602}
1603
1604
1605/*

Callers 2

ProcessInsertionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected