@@ -133,7 +133,7 @@ static void transformConstraintAttrs(CreateStmtContext *cxt,
133
133
List * constraintList );
134
134
static void transformColumnType (CreateStmtContext * cxt , ColumnDef * column );
135
135
static void setSchemaName (char * context_schema , char * * stmt_schema_name );
136
- static void transformAttachPartition (CreateStmtContext * cxt , PartitionCmd * cmd );
136
+ static void transformPartitionCmd (CreateStmtContext * cxt , PartitionCmd * cmd );
137
137
138
138
139
139
/*
@@ -2654,12 +2654,12 @@ transformAlterTableStmt(Oid relid, AlterTableStmt *stmt,
2654
2654
}
2655
2655
2656
2656
case AT_AttachPartition :
2657
+ case AT_DetachPartition :
2657
2658
{
2658
2659
PartitionCmd * partcmd = (PartitionCmd * ) cmd -> def ;
2659
2660
2660
- transformAttachPartition (& cxt , partcmd );
2661
-
2662
- /* assign transformed values */
2661
+ transformPartitionCmd (& cxt , partcmd );
2662
+ /* assign transformed value of the partition bound */
2663
2663
partcmd -> bound = cxt .partbound ;
2664
2664
}
2665
2665
@@ -3032,28 +3032,29 @@ setSchemaName(char *context_schema, char **stmt_schema_name)
3032
3032
}
3033
3033
3034
3034
/*
3035
- * transformAttachPartition
3036
- * Analyze ATTACH PARTITION ... FOR VALUES ...
3035
+ * transformPartitionCmd
3036
+ * Analyze the ATTACH/DETACH PARTITION command
3037
+ *
3038
+ * In case of the ATTACH PARTITION command, cxt->partbound is set to the
3039
+ * transformed value of cmd->bound.
3037
3040
*/
3038
3041
static void
3039
- transformAttachPartition (CreateStmtContext * cxt , PartitionCmd * cmd )
3042
+ transformPartitionCmd (CreateStmtContext * cxt , PartitionCmd * cmd )
3040
3043
{
3041
3044
Relation parentRel = cxt -> rel ;
3042
3045
3043
- /*
3044
- * We are going to try to validate the partition bound specification
3045
- * against the partition key of rel, so it better have one.
3046
- */
3046
+ /* the table must be partitioned */
3047
3047
if (parentRel -> rd_rel -> relkind != RELKIND_PARTITIONED_TABLE )
3048
3048
ereport (ERROR ,
3049
3049
(errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
3050
3050
errmsg ("\"%s\" is not partitioned" ,
3051
3051
RelationGetRelationName (parentRel ))));
3052
3052
3053
- /* transform the values */
3053
+ /* transform the partition bound, if any */
3054
3054
Assert (RelationGetPartitionKey (parentRel ) != NULL );
3055
- cxt -> partbound = transformPartitionBound (cxt -> pstate , parentRel ,
3056
- cmd -> bound );
3055
+ if (cmd -> bound != NULL )
3056
+ cxt -> partbound = transformPartitionBound (cxt -> pstate , parentRel ,
3057
+ cmd -> bound );
3057
3058
}
3058
3059
3059
3060
/*
0 commit comments