The operand types of an operator invocation are resolved following the procedure below. Note that this procedure is indirectly affected by the precedence of the involved operators. See Section 1.4 for more information.
Operand Type Resolution
Check for an exact match in the pg_operator system catalog.
If one argument of a binary operator is unknown type, then assume it is the same type as the other argument for this check. Other cases involving unknown will never find a match at this step.
Look for the best match.
Make a list of all operators of the same name for which the input types match or can be coerced to match. (unknown literals are assumed to be coercible to anything for this purpose.) If there is only one, use it; else continue to the next step.
Run through all candidates and keep those with the most exact matches on input types. Keep all candidates if none have any exact matches. If only one candidate remains, use it; else continue to the next step.
Run through all candidates and keep those with the most exact or binary-compatible matches on input types. Keep all candidates if none have any exact or binary-compatible matches. If only one candidate remains, use it; else continue to the next step.
Run through all candidates and keep those that accept preferred types at the most positions where type coercion will be required. Keep all candidates if none accept preferred types. If only one candidate remains, use it; else continue to the next step.
If any input arguments are "unknown", check the type categories accepted at those argument positions by the remaining candidates. At each position, select the "string" category if any candidate accepts that category (this bias towards string is appropriate since an unknown-type literal does look like a string). Otherwise, if all the remaining candidates accept the same type category, select that category; otherwise fail because the correct choice cannot be deduced without more clues. Also note whether any of the candidates accept a preferred data type within the selected category. Now discard operator candidates that do not accept the selected type category; furthermore, if any candidate accepts a preferred type at a given argument position, discard candidates that accept non-preferred types for that argument.
If only one candidate remains, use it. If no candidate or more than one candidate remains, then fail.