* ExecCheck - evaluate a check constraint * * For check constraints, a null result is taken as TRUE, ie the constraint * passes. * * The check constraint may have been prepared with ExecInitCheck * (possibly via ExecPrepareCheck) if the caller had it in implicit-AND * format, but a regular boolean expression prepared with ExecInitExpr or * ExecPrepareExpr works too. */
| 862 | * ExecPrepareExpr works too. |
| 863 | */ |
| 864 | bool |
| 865 | ExecCheck(ExprState *state, ExprContext *econtext) |
| 866 | { |
| 867 | Datum ret; |
| 868 | bool isnull; |
| 869 | |
| 870 | /* short-circuit (here and in ExecInitCheck) for empty restriction list */ |
| 871 | if (state == NULL) |
| 872 | return true; |
| 873 | |
| 874 | /* verify that expression was not compiled using ExecInitQual */ |
| 875 | Assert(!(state->flags & EEO_FLAG_IS_QUAL)); |
| 876 | |
| 877 | ret = ExecEvalExprSwitchContext(state, econtext, &isnull); |
| 878 | |
| 879 | if (isnull) |
| 880 | return true; |
| 881 | |
| 882 | return DatumGetBool(ret); |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | * Prepare a compiled expression for execution. This has to be called for |
no test coverage detected