to_char

Function to_char 

Source
pub fn to_char<'a, V, E, F>(
    expr: E,
    format: F,
) -> SQLExpr<'a, V, Text, E::Nullable, Scalar>
where V: SQLParam + 'a, E: Expr<'a, V>, E::SQLType: Temporal, F: Expr<'a, V>,
Expand description

TO_CHAR - formats a temporal expression as text (PostgreSQL).

Returns Text type, preserves nullability of the input expression.

§Common Format Patterns

  • YYYY - 4-digit year
  • MM - month (01-12)
  • DD - day of month (01-31)
  • HH24 - hour (00-23)
  • MI - minute (00-59)
  • SS - second (00-59)
  • Day - full day name
  • Month - full month name

§Example

use drizzle_core::expr::to_char;

// SELECT TO_CHAR(users.created_at, 'YYYY-MM-DD')
let formatted = to_char(users.created_at, "YYYY-MM-DD");