* 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 ( ) */
| 1522 | * VALUES ( <list of values> ) |
| 1523 | */ |
| 1524 | static Query * |
| 1525 | CreateInsertQuery(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 | /* |
no test coverage detected