Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-39316

Make SET TIMESTAMP accept datetime‑string values

    XMLWordPrintable

Details

    • New Feature
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • Parser, Variables
    • None

    Description

      Currently SET TIMESTAMP accepts only an integer (seconds‑since‑epoch) and rejects any other value type, including:

      • Quoted datetime strings: SET TIMESTAMP = '2000-01-21 00:00:00';
      • Calls like: SET TIMESTAMP = TIMESTAMP('2000-01-21 00:00:00');

      Suggested improvement

      Auto‑detect the value type
      • If <value> is an integer, treat it as seconds‑since‑epoch (current behavior).
      • If <value> is a valid datetime string (e.g., 'YYYY-MM-DD HH:MI:SS'), convert it internally to the corresponding Unix timestamp and use that.
        This would support:

        SET TIMESTAMP = '2000-01-21 00:00:00';
        SET TIMESTAMP = TIMESTAMP('2000-01-21 00:00:00');
        

      Fail early on wrong format

      The current workaround is to manually convert via UNIX_TIMESTAMP(), but this has problems:

      • UNIX_TIMESTAMP() can silently accept invalid or malformed datetime strings and return NULL or 0 instead of failing.
      • SET TIMESTAMP then does not fail when such a value is passed; it only emits a warning:

        Warning 1292  Incorrect datetime value: '2000-21-01 00:00:00'
        

        This makes it easy to miss configuration errors and hard to catch typos in the date string.

      Motivation / benefits

      • User‑friendliness: Users can naturally mix Unix‑epoch integers and ISO‑style datetime strings without needing to wrap everything through UNIX_TIMESTAMP().
      • Better diagnostics: The SET TIMESTAMP syntax itself can validate the datetime string and reject clearly invalid formats immediately, rather than relying on UNIX_TIMESTAMP()’s lax behavior.
      • Consistency: Other SQL‑style timestamp manipulations accept both epoch integers and string datetimes; SET TIMESTAMP should follow this pattern.

      Drawbacks of current approach

      Users must manually call UNIX_TIMESTAMP(string_value) each time, which:

      • Relies on UNIX_TIMESTAMP()’s permissive behavior, so malformed dates may be accepted silently and only produce a warning, not an error.
      • Makes it harder to debug because the warning is emitted during the UNIX_TIMESTAMP() call, not at the SET TIMESTAMP statement level.

      By supporting auto‑detected value types and stricter validation at the SET TIMESTAMP level, MariaDB can improve both usability and robustness for time‑related session configuration.

      Attachments

        Activity

          People

            midenok Aleksey Midenkov
            midenok Aleksey Midenkov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.