* Initialize cast case entry. */
| 1467 | * Initialize cast case entry. |
| 1468 | */ |
| 1469 | static void |
| 1470 | init_cast_cache_entry(CastCacheData *ccast, |
| 1471 | Oid targettypid, |
| 1472 | int32 targettypmod, |
| 1473 | Oid sourcetypid) |
| 1474 | { |
| 1475 | Oid funcoid; |
| 1476 | Oid basetypid; |
| 1477 | |
| 1478 | basetypid = getBaseType(targettypid); |
| 1479 | |
| 1480 | if (targettypid != basetypid) |
| 1481 | ccast->targettypid = targettypid; |
| 1482 | else |
| 1483 | ccast->targettypid = InvalidOid; |
| 1484 | |
| 1485 | ccast->targettypmod = targettypmod; |
| 1486 | |
| 1487 | if (sourcetypid == targettypid) |
| 1488 | ccast->without_cast = targettypmod == -1; |
| 1489 | else |
| 1490 | ccast->without_cast = false; |
| 1491 | |
| 1492 | if (!ccast->without_cast) |
| 1493 | { |
| 1494 | ccast->path = find_coercion_pathway(basetypid, |
| 1495 | sourcetypid, |
| 1496 | COERCION_ASSIGNMENT, |
| 1497 | &funcoid); |
| 1498 | |
| 1499 | if (ccast->path == COERCION_PATH_NONE) |
| 1500 | ereport(ERROR, |
| 1501 | (errcode(ERRCODE_CANNOT_COERCE), |
| 1502 | errmsg("cannot to find cast from source type \"%s\" to target type \"%s\"", |
| 1503 | format_type_be(sourcetypid), |
| 1504 | format_type_be(basetypid)))); |
| 1505 | |
| 1506 | if (ccast->path == COERCION_PATH_FUNC) |
| 1507 | { |
| 1508 | fmgr_info(funcoid, &ccast->finfo); |
| 1509 | } |
| 1510 | else if (ccast->path == COERCION_PATH_COERCEVIAIO) |
| 1511 | { |
| 1512 | bool typisvarlena; |
| 1513 | |
| 1514 | getTypeOutputInfo(sourcetypid, &funcoid, &typisvarlena); |
| 1515 | fmgr_info(funcoid, &ccast->finfo_out); |
| 1516 | |
| 1517 | getTypeInputInfo(targettypid, &funcoid, &ccast->typIOParam); |
| 1518 | fmgr_info(funcoid, &ccast->finfo_in); |
| 1519 | } |
| 1520 | |
| 1521 | if (targettypmod != -1) |
| 1522 | { |
| 1523 | ccast->path_typmod = find_typmod_coercion_function(targettypid, |
| 1524 | &funcoid); |
| 1525 | if (ccast->path_typmod == COERCION_PATH_FUNC) |
| 1526 | fmgr_info(funcoid, &ccast->finfo_typmod); |
no test coverage detected