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

Function ExecCreateTableAs

src/backend/commands/createas.c:326–595  ·  view source on GitHub ↗

* ExecCreateTableAs -- execute a CREATE TABLE AS command */

Source from the content-addressed store, hash-verified

324 * ExecCreateTableAs -- execute a CREATE TABLE AS command
325 */
326ObjectAddress
327ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
328 ParamListInfo params, QueryEnvironment *queryEnv,
329 QueryCompletion *qc)
330{
331 Query *query = castNode(Query, stmt->query);
332 IntoClause *into = stmt->into;
333 bool is_matview = (into->viewQuery != NULL);
334 DestReceiver *dest;
335 Oid save_userid = InvalidOid;
336 int save_sec_context = 0;
337 int save_nestlevel = 0;
338 ObjectAddress address;
339 List *rewritten;
340 PlannedStmt *plan;
341 QueryDesc *queryDesc;
342 Query *query_immv = NULL;
343 Oid relationOid = InvalidOid; /* relation that is modified */
344 AutoStatsCmdType cmdType = AUTOSTATS_CMDTYPE_SENTINEL; /* command type */
345
346 Assert(Gp_role != GP_ROLE_EXECUTE);
347
348 /* Check if the relation exists or not */
349 {
350 Oid nspid;
351 Oid oldrelid;
352
353 nspid = RangeVarGetCreationNamespace(into->rel);
354
355 oldrelid = get_relname_relid(into->rel->relname, nspid);
356 if (OidIsValid(oldrelid))
357 {
358 if (!stmt->if_not_exists)
359 ereport(ERROR,
360 (errcode(ERRCODE_DUPLICATE_TABLE),
361 errmsg("relation \"%s\" already exists",
362 into->rel->relname)));
363
364 /*
365 * The relation exists and IF NOT EXISTS has been specified.
366 *
367 * If we are in an extension script, insist that the pre-existing
368 * object be a member of the extension, to avoid security risks.
369 */
370 ObjectAddressSet(address, RelationRelationId, oldrelid);
371 checkMembershipInCurrentExtension(&address);
372
373 /* OK to skip */
374 ereport(NOTICE,
375 (errcode(ERRCODE_DUPLICATE_TABLE),
376 errmsg("relation \"%s\" already exists, skipping",
377 into->rel->relname)));
378 return InvalidObjectAddress;
379 }
380 }
381
382 /*
383 * Create the tuple receiver object and insert info it will need

Callers 1

ProcessUtilitySlowFunction · 0.85

Calls 15

get_relname_relidFunction · 0.85
ExecuteQueryFunction · 0.85
GetUserIdAndSecContextFunction · 0.85
SetUserIdAndSecContextFunction · 0.85
NewGUCNestLevelFunction · 0.85
check_ivm_restrictionFunction · 0.85
rewriteQueryForIMMVFunction · 0.85
QueryRewriteFunction · 0.85

Tested by

no test coverage detected