* validate_format_params * * verifies that every field specified in the table creation list is also present in the formatting string * and vice versa */
| 334 | * and vice versa |
| 335 | */ |
| 336 | static void |
| 337 | validate_format_params(FormatConfig *format_in_config, TupleDesc tupdesc) |
| 338 | { |
| 339 | ListCell *l; |
| 340 | int num_fields_in_format_string = list_length(format_in_config->fldNames); |
| 341 | int num_fields_in_table_list = tupdesc->natts; |
| 342 | |
| 343 | if (num_fields_in_format_string != num_fields_in_table_list) |
| 344 | { |
| 345 | ereport(ERROR, |
| 346 | (errcode(ERRCODE_UNDEFINED_COLUMN), |
| 347 | errmsg("mismatch in column length specification"), |
| 348 | errdetail("The fixed width formatter requires a length specification for each one of the " |
| 349 | "external table columns being used (currently %d, however format string has %d).", |
| 350 | num_fields_in_table_list, num_fields_in_format_string))); |
| 351 | } |
| 352 | |
| 353 | foreach(l, format_in_config->fldNames) |
| 354 | { |
| 355 | int i; |
| 356 | bool is_in_both_lists = false; |
| 357 | char *name = strVal(lfirst(l)); |
| 358 | for (i = 0; i < num_fields_in_table_list; i++) |
| 359 | { |
| 360 | if (namestrcmp(&(TupleDescAttr(tupdesc, i)->attname), name) == 0) |
| 361 | { |
| 362 | is_in_both_lists = true; |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (is_in_both_lists == false) |
| 368 | { |
| 369 | ereport(ERROR, |
| 370 | (errcode(ERRCODE_UNDEFINED_COLUMN), |
| 371 | errmsg("missing column definition in length specification"), |
| 372 | errdetail("The fixed width formatter requires a length specification for each one of the " |
| 373 | "external table columns being used (missing field \"%s\").", |
| 374 | name))); |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | init_format_in_config(FormatConfig *format_in_config, int ncolumns, TupleDesc tupdesc, FunctionCallInfo fcinfo) |
no test coverage detected