* ALTER TABLE ATTACH PARTITION FOR VALUES * * Return the address of the newly attached partition. */
| 21449 | * Return the address of the newly attached partition. |
| 21450 | */ |
| 21451 | static ObjectAddress |
| 21452 | ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd, |
| 21453 | AlterTableUtilityContext *context) |
| 21454 | { |
| 21455 | Relation attachrel, |
| 21456 | catalog; |
| 21457 | List *attachrel_children; |
| 21458 | List *partConstraint; |
| 21459 | SysScanDesc scan; |
| 21460 | ScanKeyData skey; |
| 21461 | AttrNumber attno; |
| 21462 | int natts; |
| 21463 | TupleDesc tupleDesc; |
| 21464 | ObjectAddress address; |
| 21465 | const char *trigger_name; |
| 21466 | Oid defaultPartOid; |
| 21467 | List *partBoundConstraint; |
| 21468 | ParseState *pstate = make_parsestate(NULL); |
| 21469 | |
| 21470 | pstate->p_sourcetext = context->queryString; |
| 21471 | |
| 21472 | /* |
| 21473 | * We must lock the default partition if one exists, because attaching a |
| 21474 | * new partition will change its partition constraint. |
| 21475 | */ |
| 21476 | defaultPartOid = |
| 21477 | get_default_oid_from_partdesc(RelationGetPartitionDesc(rel, true)); |
| 21478 | if (OidIsValid(defaultPartOid)) |
| 21479 | LockRelationOid(defaultPartOid, AccessExclusiveLock); |
| 21480 | |
| 21481 | attachrel = table_openrv(cmd->name, AccessExclusiveLock); |
| 21482 | |
| 21483 | /* |
| 21484 | * XXX I think it'd be a good idea to grab locks on all tables referenced |
| 21485 | * by FKs at this point also. |
| 21486 | */ |
| 21487 | |
| 21488 | /* |
| 21489 | * Must be owner of both parent and source table -- parent was checked by |
| 21490 | * ATSimplePermissions call in ATPrepCmd |
| 21491 | */ |
| 21492 | ATSimplePermissions(attachrel, ATT_TABLE | ATT_FOREIGN_TABLE); |
| 21493 | |
| 21494 | /* A partition can only have one parent */ |
| 21495 | if (attachrel->rd_rel->relispartition) |
| 21496 | ereport(ERROR, |
| 21497 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 21498 | errmsg("\"%s\" is already a partition", |
| 21499 | RelationGetRelationName(attachrel)))); |
| 21500 | |
| 21501 | if (OidIsValid(attachrel->rd_rel->reloftype)) |
| 21502 | ereport(ERROR, |
| 21503 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 21504 | errmsg("cannot attach a typed table as partition"))); |
| 21505 | |
| 21506 | /* |
| 21507 | * Table being attached should not already be part of inheritance; either |
| 21508 | * as a child table... |
no test coverage detected