Skip to content

Type date_trunc inputs, outputs, and nullability #58

Description

@alexeichhorn

Problem

date_trunc currently accepts any value type and always claims to return that same Rust type:

pub fn date_trunc<T>(part: impl IntoExpr<String>, value: impl IntoExpr<T>) -> Expr<T>

This allows invalid calls such as date_trunc("day", integer_column) to compile. DATE and TIME inputs can also receive an incorrect output type after PostgreSQL overload resolution or implicit casts.

The precision argument is fixed to required String, so a nullable precision expression is rejected even though PostgreSQL returns NULL when it is NULL.

Expected behavior

  • Support the direct PostgreSQL input/result pairs:
    • TIMESTAMP → TIMESTAMP
    • TIMESTAMPTZ → TIMESTAMPTZ
    • INTERVAL → INTERVAL
  • Preserve optional output when the precision or temporal value is nullable.
  • Reject unrelated inputs at compile time.
  • Reject DATE and TIME unless dbkit emits an explicit, stable cast with the correct output type.
  • Cover required/nullable combinations for all supported base types.
  • Decide whether to expose PostgreSQL's timestamptz timezone argument as part of the same typed contract.

PostgreSQL date_trunc signatures

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions