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

Function CreateInsertQuery

pg_documentdb/src/commands/insert.c:1524–1557  ·  view source on GitHub ↗

* Creates a Query for the purposes of inserting a document. This takes * the form * INSERT INTO (shard_key_value, object_id, document, creation_time) * VALUES ( ) */

Source from the content-addressed store, hash-verified

1522 * VALUES ( <list of values> )
1523 */
1524static Query *
1525CreateInsertQuery(MongoCollection *collection, Oid shardOid, List *valuesLists)
1526{
1527 Query *query = makeNode(Query);
1528 query->commandType = CMD_INSERT;
1529 query->querySource = QSRC_ORIGINAL;
1530 query->canSetTag = true;
1531
1532#if PG_VERSION_NUM >= 160000
1533 RangeTblEntry *rte = CreateBaseTableRteForInsert(collection, shardOid,
1534 &query->rteperminfos);
1535#else
1536 RangeTblEntry *rte = CreateBaseTableRteForInsert(collection, shardOid, NULL);
1537#endif
1538
1539 RangeTblEntry *valuesRte = CreateValueRteForInsert(collection, valuesLists);
1540
1541 query->rtable = list_make2(rte, valuesRte);
1542 query->resultRelation = 1;
1543
1544 RangeTblRef *valuesRteRef = makeNode(RangeTblRef);
1545 valuesRteRef->rtindex = 2;
1546 List *fromList = list_make1(valuesRteRef);
1547
1548 query->jointree = makeFromExpr(fromList, NULL);
1549 query->targetList = CreateTargetListForInsert(collection);
1550
1551 /* In order to use a portal & SPI we create a returning list of a const */
1552 query->returningList = list_make1(
1553 makeTargetEntry((Expr *) makeConst(INT4OID, -1, InvalidOid, 4, Int32GetDatum(1),
1554 false, true), 1, "intVal", false)
1555 );
1556 return query;
1557}
1558
1559
1560/*

Callers 2

ProcessInsertionFunction · 0.85

Calls 3

CreateValueRteForInsertFunction · 0.85

Tested by

no test coverage detected