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

Function transformUpdateStmt

src/backend/parser/analyze.c:2808–2880  ·  view source on GitHub ↗

* transformUpdateStmt - * transforms an update statement */

Source from the content-addressed store, hash-verified

2806 * transforms an update statement
2807 */
2808static Query *
2809transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
2810{
2811 Query *qry = makeNode(Query);
2812 ParseNamespaceItem *nsitem;
2813 Node *qual;
2814
2815 qry->commandType = CMD_UPDATE;
2816 pstate->p_is_insert = false;
2817 pstate->p_is_on_conflict_update = false;
2818
2819 /* process the WITH clause independently of all else */
2820 if (stmt->withClause)
2821 {
2822 qry->hasRecursive = stmt->withClause->recursive;
2823 qry->cteList = transformWithClause(pstate, stmt->withClause);
2824 qry->hasModifyingCTE = pstate->p_hasModifyingCTE;
2825
2826 /*
2827 * Since GPDB currently only support a single writer gang, only one
2828 * writable clause is permitted per CTE. Once we get flexible gangs
2829 * with more than one writer gang we can lift this restriction.
2830 */
2831 if (pstate->p_hasModifyingCTE)
2832 ereport(ERROR,
2833 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2834 errmsg("writable CTE queries cannot be themselves writable"),
2835 errdetail("Apache Cloudberry currently only support CTEs with one writable clause, called in a non-writable context."),
2836 errhint("Rewrite the query to only include one writable clause.")));
2837 }
2838
2839 qry->resultRelation = setTargetTable(pstate, stmt->relation,
2840 stmt->relation->inh,
2841 true,
2842 ACL_UPDATE);
2843 nsitem = pstate->p_target_nsitem;
2844
2845 /* subqueries in FROM cannot access the result relation */
2846 nsitem->p_lateral_only = true;
2847 nsitem->p_lateral_ok = false;
2848
2849 /*
2850 * the FROM clause is non-standard SQL syntax. We used to be able to do
2851 * this with REPLACE in POSTQUEL so we keep the feature.
2852 */
2853 transformFromClause(pstate, stmt->fromClause);
2854
2855 /* remaining clauses can reference the result relation normally */
2856 nsitem->p_lateral_only = false;
2857 nsitem->p_lateral_ok = true;
2858
2859 qual = transformWhereClause(pstate, stmt->whereClause,
2860 EXPR_KIND_WHERE, "WHERE");
2861
2862 qry->returningList = transformReturningList(pstate, stmt->returningList);
2863
2864 /*
2865 * Now we are done with SELECT-like processing, and can get on with

Callers 1

transformStmtFunction · 0.85

Calls 12

transformWithClauseFunction · 0.85
setTargetTableFunction · 0.85
transformFromClauseFunction · 0.85
transformWhereClauseFunction · 0.85
transformReturningListFunction · 0.85
makeFromExprFunction · 0.85
assign_query_collationsFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50
errdetailFunction · 0.50
errhintFunction · 0.50

Tested by

no test coverage detected