* Check expected (query runtime) tupdesc suitable for Connectby */
| 1421 | * Check expected (query runtime) tupdesc suitable for Connectby |
| 1422 | */ |
| 1423 | static void |
| 1424 | validateConnectbyTupleDesc(TupleDesc td, bool show_branch, bool show_serial) |
| 1425 | { |
| 1426 | int serial_column = 0; |
| 1427 | |
| 1428 | if (show_serial) |
| 1429 | serial_column = 1; |
| 1430 | |
| 1431 | /* are there the correct number of columns */ |
| 1432 | if (show_branch) |
| 1433 | { |
| 1434 | if (td->natts != (CONNECTBY_NCOLS + serial_column)) |
| 1435 | ereport(ERROR, |
| 1436 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 1437 | errmsg("invalid return type"), |
| 1438 | errdetail("Query-specified return tuple has " \ |
| 1439 | "wrong number of columns."))); |
| 1440 | } |
| 1441 | else |
| 1442 | { |
| 1443 | if (td->natts != CONNECTBY_NCOLS_NOBRANCH + serial_column) |
| 1444 | ereport(ERROR, |
| 1445 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 1446 | errmsg("invalid return type"), |
| 1447 | errdetail("Query-specified return tuple has " \ |
| 1448 | "wrong number of columns."))); |
| 1449 | } |
| 1450 | |
| 1451 | /* check that the types of the first two columns match */ |
| 1452 | if (TupleDescAttr(td, 0)->atttypid != TupleDescAttr(td, 1)->atttypid) |
| 1453 | ereport(ERROR, |
| 1454 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 1455 | errmsg("invalid return type"), |
| 1456 | errdetail("First two columns must be the same type."))); |
| 1457 | |
| 1458 | /* check that the type of the third column is INT4 */ |
| 1459 | if (TupleDescAttr(td, 2)->atttypid != INT4OID) |
| 1460 | ereport(ERROR, |
| 1461 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 1462 | errmsg("invalid return type"), |
| 1463 | errdetail("Third column must be type %s.", |
| 1464 | format_type_be(INT4OID)))); |
| 1465 | |
| 1466 | /* check that the type of the fourth column is TEXT if applicable */ |
| 1467 | if (show_branch && TupleDescAttr(td, 3)->atttypid != TEXTOID) |
| 1468 | ereport(ERROR, |
| 1469 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 1470 | errmsg("invalid return type"), |
| 1471 | errdetail("Fourth column must be type %s.", |
| 1472 | format_type_be(TEXTOID)))); |
| 1473 | |
| 1474 | /* check that the type of the fifth column is INT4 */ |
| 1475 | if (show_branch && show_serial && |
| 1476 | TupleDescAttr(td, 4)->atttypid != INT4OID) |
| 1477 | ereport(ERROR, |
| 1478 | (errcode(ERRCODE_DATATYPE_MISMATCH), |
| 1479 | errmsg("query-specified return tuple not valid for Connectby: " |
| 1480 | "fifth column must be type %s", |
no test coverage detected