1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Allow non-deterministic function in CHECK constraints. It turns out that

PostgreSQL, MySQL, and SQLServer all allow this.  We should be the the
exception.  Ticket [830277d9db6c3ba1]

FossilOrigin-Name: 8c8ce526adb60b8061e55151599ca8b11f1ec2e968d3bacc73a2a249e9e95ee1
This commit is contained in:
drh
2020-01-18 21:34:31 +00:00
parent f71eb2091f
commit fe7046044c
3 changed files with 13 additions and 10 deletions

View File

@@ -868,11 +868,14 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
ExprSetProperty(pExpr,EP_ConstFunc);
}
if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
/* Date/time functions that use 'now', and other functions like
/* Clearly non-deterministic functions like random(), but also
** date/time functions that use 'now', and other functions like
** sqlite_version() that might change over time cannot be used
** in an index. */
** in an index or generated column. Curiously, they can be used
** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all
** all this. */
sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
NC_SelfRef, 0);
NC_IdxExpr|NC_PartIdx|NC_GenCol, 0);
}else{
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
pExpr->op2 = pNC->ncFlags & NC_SelfRef;