* transformInsertStmt - * transform an Insert Statement */
| 623 | * transform an Insert Statement |
| 624 | */ |
| 625 | static Query * |
| 626 | transformInsertStmt(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; |
no test coverage detected