* Apply cast rules to a value */
| 1534 | * Apply cast rules to a value |
| 1535 | */ |
| 1536 | static Datum |
| 1537 | cast_value(CastCacheData *ccast, Datum value, bool isnull) |
| 1538 | { |
| 1539 | if (!isnull && !ccast->without_cast) |
| 1540 | { |
| 1541 | if (ccast->path == COERCION_PATH_FUNC) |
| 1542 | value = FunctionCall1(&ccast->finfo, value); |
| 1543 | else if (ccast->path == COERCION_PATH_RELABELTYPE) |
| 1544 | { |
| 1545 | /* do nothing */ |
| 1546 | } |
| 1547 | else if (ccast->path == COERCION_PATH_COERCEVIAIO) |
| 1548 | { |
| 1549 | char *str; |
| 1550 | |
| 1551 | str = OutputFunctionCall(&ccast->finfo_out, value); |
| 1552 | value = InputFunctionCall(&ccast->finfo_in, |
| 1553 | str, |
| 1554 | ccast->typIOParam, |
| 1555 | ccast->targettypmod); |
| 1556 | } |
| 1557 | else |
| 1558 | ereport(ERROR, |
| 1559 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1560 | errmsg("unsupported cast path yet %d", ccast->path))); |
| 1561 | |
| 1562 | if (ccast->targettypmod != -1 && ccast->path_typmod == COERCION_PATH_FUNC) |
| 1563 | value = FunctionCall3(&ccast->finfo_typmod, |
| 1564 | value, |
| 1565 | Int32GetDatum(ccast->targettypmod), |
| 1566 | BoolGetDatum(true)); |
| 1567 | } |
| 1568 | |
| 1569 | if (ccast->targettypid != InvalidOid) |
| 1570 | domain_check(value, isnull, ccast->targettypid, NULL, NULL); |
| 1571 | |
| 1572 | return value; |
| 1573 | } |
| 1574 | |
| 1575 | /* |
| 1576 | * CALL statement is relatily slow in PLpgSQL - due repated parsing, planning. |
no test coverage detected