* transformPartitionBound * * Transform a partition bound specification */
| 5208 | * Transform a partition bound specification |
| 5209 | */ |
| 5210 | PartitionBoundSpec * |
| 5211 | transformPartitionBound(ParseState *pstate, Relation parent, PartitionKey key, |
| 5212 | PartitionBoundSpec *spec) |
| 5213 | { |
| 5214 | PartitionBoundSpec *result_spec; |
| 5215 | char strategy = get_partition_strategy(key); |
| 5216 | int partnatts = get_partition_natts(key); |
| 5217 | List *partexprs = get_partition_exprs(key); |
| 5218 | |
| 5219 | /* Avoid scribbling on input */ |
| 5220 | result_spec = copyObject(spec); |
| 5221 | |
| 5222 | if (spec->is_default) |
| 5223 | { |
| 5224 | /* |
| 5225 | * Hash partitioning does not support a default partition; there's no |
| 5226 | * use case for it (since the set of partitions to create is perfectly |
| 5227 | * defined), and if users do get into it accidentally, it's hard to |
| 5228 | * back out from it afterwards. |
| 5229 | */ |
| 5230 | if (strategy == PARTITION_STRATEGY_HASH) |
| 5231 | ereport(ERROR, |
| 5232 | (errcode(ERRCODE_INVALID_TABLE_DEFINITION), |
| 5233 | errmsg("a hash-partitioned table may not have a default partition"))); |
| 5234 | |
| 5235 | /* |
| 5236 | * In case of the default partition, parser had no way to identify the |
| 5237 | * partition strategy. Assign the parent's strategy to the default |
| 5238 | * partition bound spec. |
| 5239 | */ |
| 5240 | result_spec->strategy = strategy; |
| 5241 | |
| 5242 | return result_spec; |
| 5243 | } |
| 5244 | |
| 5245 | if (strategy == PARTITION_STRATEGY_HASH) |
| 5246 | { |
| 5247 | if (spec->strategy != PARTITION_STRATEGY_HASH) |
| 5248 | ereport(ERROR, |
| 5249 | (errcode(ERRCODE_INVALID_TABLE_DEFINITION), |
| 5250 | errmsg("invalid bound specification for a hash partition"), |
| 5251 | parser_errposition(pstate, exprLocation((Node *) spec)))); |
| 5252 | |
| 5253 | if (spec->modulus <= 0) |
| 5254 | ereport(ERROR, |
| 5255 | (errcode(ERRCODE_INVALID_TABLE_DEFINITION), |
| 5256 | errmsg("modulus for hash partition must be an integer value greater than zero"))); |
| 5257 | |
| 5258 | Assert(spec->remainder >= 0); |
| 5259 | |
| 5260 | if (spec->remainder >= spec->modulus) |
| 5261 | ereport(ERROR, |
| 5262 | (errcode(ERRCODE_INVALID_TABLE_DEFINITION), |
| 5263 | errmsg("remainder for hash partition must be less than modulus"))); |
| 5264 | } |
| 5265 | else if (strategy == PARTITION_STRATEGY_LIST) |
| 5266 | { |
| 5267 | ListCell *cell; |
no test coverage detected