MCPcopy Create free account
hub / github.com/apache/cloudberry / transformInsertStmt

Function transformInsertStmt

src/backend/parser/analyze.c:625–1072  ·  view source on GitHub ↗

* transformInsertStmt - * transform an Insert Statement */

Source from the content-addressed store, hash-verified

623 * transform an Insert Statement
624 */
625static Query *
626transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
627{
628 Query *qry = makeNode(Query);
629 SelectStmt *selectStmt = (SelectStmt *) stmt->selectStmt;
630 List *exprList = NIL;
631 bool isGeneralSelect;
632 List *sub_rtable;
633 List *sub_namespace;
634 List *icolumns;
635 List *attrnos;
636 ParseNamespaceItem *nsitem;
637 RangeTblEntry *rte;
638 ListCell *icols;
639 ListCell *attnos;
640 ListCell *lc;
641 bool isOnConflictUpdate;
642 AclMode targetPerms;
643
644 /* There can't be any outer WITH to worry about */
645 Assert(pstate->p_ctenamespace == NIL);
646
647 qry->commandType = CMD_INSERT;
648 pstate->p_is_insert = true;
649 pstate->p_is_on_conflict_update = false;
650
651 /* process the WITH clause independently of all else */
652 if (stmt->withClause)
653 {
654 qry->hasRecursive = stmt->withClause->recursive;
655 qry->cteList = transformWithClause(pstate, stmt->withClause);
656 qry->hasModifyingCTE = pstate->p_hasModifyingCTE;
657
658 /*
659 * Since GPDB currently only support a single writer gang, only one
660 * writable clause is permitted per CTE. Once we get flexible gangs
661 * with more than one writer gang we can lift this restriction.
662 */
663 if (pstate->p_hasModifyingCTE)
664 ereport(ERROR,
665 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
666 errmsg("writable CTE queries cannot be themselves writable"),
667 errdetail("Apache Cloudberry currently only support CTEs with one writable clause, called in a non-writable context."),
668 errhint("Rewrite the query to only include one writable clause.")));
669 }
670
671 qry->override = stmt->override;
672
673 isOnConflictUpdate = (stmt->onConflictClause &&
674 stmt->onConflictClause->action == ONCONFLICT_UPDATE);
675
676 /*
677 * We have three cases to deal with: DEFAULT VALUES (selectStmt == NULL),
678 * VALUES list, or general SELECT input. We special-case VALUES, both for
679 * efficiency and so we can handle DEFAULT specifications.
680 *
681 * The grammar allows attaching ORDER BY, LIMIT, FOR UPDATE, or WITH to a
682 * VALUES clause. If we have any of those, treat it as a general SELECT;

Callers 1

transformStmtFunction · 0.85

Calls 15

transformWithClauseFunction · 0.85
setTargetTableFunction · 0.85
checkInsertTargetsFunction · 0.85
list_lengthFunction · 0.85
make_parsestateFunction · 0.85
transformStmtFunction · 0.85
free_parsestateFunction · 0.85
makeAliasFunction · 0.85
addNSItemToQueryFunction · 0.85
exprTypeFunction · 0.85
makeVarFromTargetEntryFunction · 0.85

Tested by

no test coverage detected