| 2088 | */ |
| 2089 | |
| 2090 | static Oid |
| 2091 | findTypeInputFunction(List *procname, Oid typeOid) |
| 2092 | { |
| 2093 | Oid argList[3]; |
| 2094 | Oid procOid; |
| 2095 | Oid procOid2; |
| 2096 | |
| 2097 | /* |
| 2098 | * Input functions can take a single argument of type CSTRING, or three |
| 2099 | * arguments (string, typioparam OID, typmod). Whine about ambiguity if |
| 2100 | * both forms exist. |
| 2101 | */ |
| 2102 | argList[0] = CSTRINGOID; |
| 2103 | argList[1] = OIDOID; |
| 2104 | argList[2] = INT4OID; |
| 2105 | |
| 2106 | procOid = LookupFuncName(procname, 1, argList, true); |
| 2107 | procOid2 = LookupFuncName(procname, 3, argList, true); |
| 2108 | if (OidIsValid(procOid)) |
| 2109 | { |
| 2110 | if (OidIsValid(procOid2)) |
| 2111 | ereport(ERROR, |
| 2112 | (errcode(ERRCODE_AMBIGUOUS_FUNCTION), |
| 2113 | errmsg("type input function %s has multiple matches", |
| 2114 | NameListToString(procname)))); |
| 2115 | } |
| 2116 | else |
| 2117 | { |
| 2118 | procOid = procOid2; |
| 2119 | /* If not found, reference the 1-argument signature in error msg */ |
| 2120 | if (!OidIsValid(procOid)) |
| 2121 | ereport(ERROR, |
| 2122 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 2123 | errmsg("function %s does not exist", |
| 2124 | func_signature_string(procname, 1, NIL, argList)))); |
| 2125 | } |
| 2126 | |
| 2127 | /* Input functions must return the target type. */ |
| 2128 | if (get_func_rettype(procOid) != typeOid) |
| 2129 | ereport(ERROR, |
| 2130 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), |
| 2131 | errmsg("type input function %s must return type %s", |
| 2132 | NameListToString(procname), format_type_be(typeOid)))); |
| 2133 | |
| 2134 | /* |
| 2135 | * Print warnings if any of the type's I/O functions are marked volatile. |
| 2136 | * There is a general assumption that I/O functions are stable or |
| 2137 | * immutable; this allows us for example to mark record_in/record_out |
| 2138 | * stable rather than volatile. Ideally we would throw errors not just |
| 2139 | * warnings here; but since this check is new as of 9.5, and since the |
| 2140 | * volatility marking might be just an error-of-omission and not a true |
| 2141 | * indication of how the function behaves, we'll let it pass as a warning |
| 2142 | * for now. |
| 2143 | */ |
| 2144 | if (func_volatile(procOid) == PROVOLATILE_VOLATILE) |
| 2145 | ereport(WARNING, |
| 2146 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), |
| 2147 | errmsg("type input function %s should not be volatile", |
no test coverage detected