Skip to content

Commit b34c046

Browse files
author
hackorum
committed
Apply restrict_nonimutable_in_check_constraint.patch
1 parent 31878cc commit b34c046

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/backend/parser/parse_expr.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,15 @@ transformMinMaxExpr(ParseState *pstate, MinMaxExpr *m)
23142314
static Node *
23152315
transformSQLValueFunction(ParseState *pstate, SQLValueFunction *svf)
23162316
{
2317+
/*
2318+
* All SQL value functions are stable so we reject them in check
2319+
* constraint expressions.
2320+
*/
2321+
if (pstate->p_expr_kind == EXPR_KIND_CHECK_CONSTRAINT)
2322+
ereport(ERROR,
2323+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2324+
errmsg("mutable functions are not allowed in check constraints")));
2325+
23172326
/*
23182327
* All we need to do is insert the correct result type and (where needed)
23192328
* validate the typmod, so we just modify the node in-place.

‎src/backend/parser/parse_func.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,13 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
275275
&nvargs, &vatype,
276276
&declared_arg_types, &argdefaults);
277277

278+
/* mutable functions are not allowed in constraint expressions */
279+
if (pstate->p_expr_kind == EXPR_KIND_CHECK_CONSTRAINT &&
280+
func_volatile(funcid) != PROVOLATILE_IMMUTABLE)
281+
ereport(ERROR,
282+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
283+
errmsg("mutable functions are not allowed in constraint expression")));
284+
278285
cancel_parser_errposition_callback(&pcbstate);
279286

280287
/*

0 commit comments

Comments
 (0)