Skip to main content

is_datetime_invocation_safe_for_schema

Function is_datetime_invocation_safe_for_schema 

Source
pub fn is_datetime_invocation_safe_for_schema(
    function_name: &str,
    args: &[SqliteValue],
) -> bool
Expand description

Return whether an evaluated built-in date/time call is safe in a schema expression whose value must remain stable for the lifetime of the schema.

SQLite’s date/time functions are conditionally deterministic. Fixed text, numeric, and row-derived values are safe, but the following forms consult wall-clock or host-local state and must not be used while maintaining an expression index, partial index, generated column, or CHECK constraint:

  • an omitted time value (for example, date() or strftime('%Y'));
  • now as a time value;
  • subsec or subsecond in the first time-value position, where SQLite treats it as shorthand for the current time with subsecond precision;
  • localtime or utc in a modifier position.

The argument layout is function-specific: strftime’s format occupies args[0], while both timediff arguments are time values and neither is a modifier. NULLs preserve SQLite’s left-to-right short-circuit behaviour: a NULL encountered before a conditional feature makes the call return NULL without consulting that feature.

Names other than the seven built-in date/time functions return true. Callers that permit user-defined overrides must resolve function identity before relying on this helper; a custom function merely named date is not necessarily governed by SQLite’s built-in date/time rules.