compatible_oper() * given an opname and input datatypes, find a compatible binary operator * * This is tighter than oper() because it will not return an operator that * requires coercion of the input datatypes (but binary-compatible operators * are accepted). Otherwise, the semantics are the same. */
| 459 | * are accepted). Otherwise, the semantics are the same. |
| 460 | */ |
| 461 | Operator |
| 462 | compatible_oper(ParseState *pstate, List *op, Oid arg1, Oid arg2, |
| 463 | bool noError, int location) |
| 464 | { |
| 465 | Operator optup; |
| 466 | Form_pg_operator opform; |
| 467 | |
| 468 | /* oper() will find the best available match */ |
| 469 | optup = oper(pstate, op, arg1, arg2, noError, location); |
| 470 | if (optup == (Operator) NULL) |
| 471 | return (Operator) NULL; /* must be noError case */ |
| 472 | |
| 473 | /* but is it good enough? */ |
| 474 | opform = (Form_pg_operator) GETSTRUCT(optup); |
| 475 | if (IsBinaryCoercible(arg1, opform->oprleft) && |
| 476 | IsBinaryCoercible(arg2, opform->oprright)) |
| 477 | return optup; |
| 478 | |
| 479 | /* nope... */ |
| 480 | ReleaseSysCache(optup); |
| 481 | |
| 482 | if (!noError) |
| 483 | ereport(ERROR, |
| 484 | (errcode(ERRCODE_UNDEFINED_FUNCTION), |
| 485 | errmsg("operator requires run-time type coercion: %s", |
| 486 | op_signature_string(op, 'b', arg1, arg2)), |
| 487 | parser_errposition(pstate, location))); |
| 488 | |
| 489 | return (Operator) NULL; |
| 490 | } |
| 491 | |
| 492 | /* compatible_oper_opid() -- get OID of a binary operator |
| 493 | * |
no test coverage detected