OtterMind/Chat2DB · error · IllegalArgumentException

Invalid MySQL default value: {value}

Error message

Invalid MySQL default value: {value}

What it means

Thrown by MysqlSqlGuards.requireNumericDefault when a raw DEFAULT literal (for a numeric-ish column, where quoting would change semantics) fails the NUMERIC_DEFAULT_PATTERN. The pattern accepts decimals/scientific, 0x hex, x'/b' literals, and TRUE/FALSE; anything else is rejected because it cannot be safely interpolated unquoted into the DEFAULT clause.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlSqlGuards.java:53

    /**
     * Validate a strict MySQL name token (ENGINE / CHARACTER SET / COLLATE style positions where
     * escaping is impossible by design).
     */
    public static String requireMysqlName(String value, String what) {
        if (value == null || !MYSQL_NAME_PATTERN.matcher(value).matches()) {
            throw new IllegalArgumentException("Invalid MySQL " + what + ": " + value);
        }
        return value;
    }

    /**
     * Validate a raw DEFAULT literal for numeric-ish columns (positions where quoting would change
     * semantics). Accepts decimal/scientific numbers, hex and bit literals, TRUE/FALSE.
     */
    public static String requireNumericDefault(String value) {
        if (value == null || !NUMERIC_DEFAULT_PATTERN.matcher(value.trim()).matches()) {
            throw new IllegalArgumentException("Invalid MySQL default value: " + value);
        }
        return value;
    }

    /**
     * Validate content of a b'...' bit literal.
     */
    public static String requireBitLiteral(String value) {
        if (value == null || !BIT_LITERAL_PATTERN.matcher(value).matches()) {
            throw new IllegalArgumentException("Invalid MySQL bit literal: " + value);
        }
        return value;
    }

    /**
     * Validate the digits of a 0x... hex literal (the template adds the 0x prefix).
     */
    public static String requireHexDigits(String value) {

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Route function/expression defaults (NOW(), etc.) through the quoted-string or expression path, not requireNumericDefault.
  2. Validate the default against the column's data type before selecting the numeric-guard path.
  3. For numeric columns, ensure the default is a plain number, hex, bit literal, or TRUE/FALSE.
  4. Trim the value and strip any surrounding quotes before validation.

Example fix

// before
MysqlSqlGuards.requireNumericDefault(defaultValue);

// after
String d = StringUtils.trimToNull(defaultValue);
if (d == null || !d.matches("^([+-]?(\\d+(\\.\\d+)?|\\.\\d+)([eE][+-]?\\d+)?|0[xX][0-9a-fA-F]+|[xX]'[0-9a-fA-F]*'|[bB]'[01]*'|(?i:TRUE|FALSE))$")) {
    throw new IllegalArgumentException("Invalid MySQL default value: " + defaultValue);
}
MysqlSqlGuards.requireNumericDefault(d);
Defensive patterns

Strategy: validation

Validate before calling

String d = StringUtils.trimToNull(value);
if (d == null || !d.matches("^([+-]?(\\d+(\\.\\d+)?|\\.\\d+)([eE][+-]?\\d+)?|0[xX][0-9a-fA-F]+|[xX]'[0-9a-fA-F]*'|[bB]'[01]*'|(?i:TRUE|FALSE))$")) {
    throw new IllegalArgumentException("Invalid MySQL default value: " + value);
}
MysqlSqlGuards.requireNumericDefault(d);

Type guard

static boolean isNumericDefault(String value) {
    return value != null && value.trim().matches("^([+-]?(\\d+(\\.\\d+)?|\\.\\d+)([eE][+-]?\\d+)?|0[xX][0-9a-fA-F]+|[xX]'[0-9a-fA-F]*'|[bB]'[01]*'|(?i:TRUE|FALSE))$");
}

Prevention

When it happens

Trigger: Calling requireNumericDefault(value) with a non-numeric expression such as a SQL function (NOW(), CURRENT_TIMESTAMP), a quoted string, an arithmetic expression, or a value with illegal characters. The value is trimmed first, so leading/trailing spaces are tolerated.

Common situations: A column DEFAULT specified as a string for a numeric column; a frontend default-value field that accepts arbitrary expressions and forwards them raw; mixing up string defaults (which should be quoted elsewhere) with numeric defaults.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/572cd01243d03440. Report an issue: GitHub.