SQL Expressions: Allow more functions (#102011)

I used Cursor and Claude 3.7 thinking to expand the list of functions
we allow. Specifically I needed `abs`.

TODO: Check each of these in the official MySQL docs to ensure they
are all safe:
eg. this doc: https://dev.mysql.com/doc/refman/8.4/en/flow-control-functions.html#operator_case
This commit is contained in:
Sam Jewell
2025-03-12 11:39:48 +00:00
committed by GitHub
parent dacb25ec2a
commit 4bd5f29e05

View File

@ -136,17 +136,55 @@ func allowedFunction(f *sqlparser.FuncExpr) (b bool) {
b = true // so don't have to return true in every case but default
switch strings.ToLower(f.Name.String()) {
case "if":
// Conditional functions
case "if", "coalesce", "ifnull", "nullif":
return
// Aggregation functions
case "sum", "avg", "count", "min", "max":
return
case "coalesce":
case "stddev", "std", "stddev_pop":
return
case "variance", "var_pop":
return
// Mathematical functions
case "abs":
return
case "round", "floor", "ceiling", "ceil":
return
case "sqrt", "pow", "power":
return
case "mod", "log", "log10", "exp":
return
case "sign":
return
// String functions
case "concat", "length", "char_length":
return
case "lower", "upper":
return
case "substring", "trim":
return
// Date functions
case "str_to_date":
return
case "date_format", "now", "curdate", "curtime":
return
case "date_add", "date_sub":
return
case "year", "month", "day", "weekday":
return
case "datediff":
return
case "unix_timestamp", "from_unixtime":
return
// Type conversion
case "cast", "convert":
return
default:
return false