* ExecCreateTableAs -- execute a CREATE TABLE AS command */
| 324 | * ExecCreateTableAs -- execute a CREATE TABLE AS command |
| 325 | */ |
| 326 | ObjectAddress |
| 327 | ExecCreateTableAs(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 |
no test coverage detected