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

Function transformTableLikeClause

src/backend/parser/parse_utilcmd.c:1069–1360  ·  view source on GitHub ↗

* transformTableLikeClause * * Change the LIKE portion of a CREATE TABLE statement into * column definitions that recreate the user defined column portions of * . Also, if there are any LIKE options that we can't fully * process at this point, add the TableLikeClause to cxt->likeclauses, which * will cause utility.c to call expandTableLikeClause() after the new * table

Source from the content-addressed store, hash-verified

1067 * GPDB: if forceBareCol is true we disallow inheriting any indexes/constr/defaults.
1068 */
1069static void
1070transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_clause,
1071 bool forceBareCol, CreateStmt *stmt)
1072{
1073 AttrNumber parent_attno;
1074 Relation relation;
1075 TupleDesc tupleDesc;
1076 AclResult aclresult;
1077 char *comment;
1078 ParseCallbackState pcbstate;
1079
1080 setup_parser_errposition_callback(&pcbstate, cxt->pstate,
1081 table_like_clause->relation->location);
1082
1083 /* LIKE INCLUDING is not supported for external tables */
1084 if (forceBareCol && table_like_clause->options != 0)
1085 ereport(ERROR,
1086 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1087 errmsg("LIKE INCLUDING may not be used with this kind of relation")));
1088
1089 /*
1090 * CBDB: Support CREATE FOREIGN TABLE LIKE.
1091 */
1092#if 0
1093 /* we could support LIKE in many cases, but worry about it another day */
1094 if (cxt->isforeign)
1095 ereport(ERROR,
1096 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1097 errmsg("LIKE is not supported for creating foreign tables")));
1098#endif
1099
1100 /* Open the relation referenced by the LIKE clause */
1101 relation = relation_openrv(table_like_clause->relation, AccessShareLock);
1102
1103 if (relation->rd_rel->relkind != RELKIND_RELATION &&
1104 relation->rd_rel->relkind != RELKIND_DIRECTORY_TABLE &&
1105 relation->rd_rel->relkind != RELKIND_VIEW &&
1106 relation->rd_rel->relkind != RELKIND_MATVIEW &&
1107 relation->rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1108 relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1109 relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1110 ereport(ERROR,
1111 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1112 errmsg("\"%s\" is not a table, directory table, view, materialized view, composite type, or foreign table",
1113 RelationGetRelationName(relation))));
1114
1115 cancel_parser_errposition_callback(&pcbstate);
1116
1117 /*
1118 * Check for privileges
1119 */
1120 if (relation->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1121 {
1122 aclresult = pg_type_aclcheck(relation->rd_rel->reltype, GetUserId(),
1123 ACL_USAGE);
1124 if (aclresult != ACLCHECK_OK)
1125 aclcheck_error(aclresult, OBJECT_TYPE,
1126 RelationGetRelationName(relation));

Callers 2

transformCreateStmtFunction · 0.85

Calls 15

relation_openrvFunction · 0.85
pg_type_aclcheckFunction · 0.85
GetUserIdFunction · 0.85
aclcheck_errorFunction · 0.85
pg_class_aclcheckFunction · 0.85
get_relkind_objtypeFunction · 0.85
makeTypeNameFromOidFunction · 0.85
lappendFunction · 0.85
getIdentitySequenceFunction · 0.85
sequence_optionsFunction · 0.85

Tested by

no test coverage detected