Skip to main content

extract

Function extract 

Source
pub fn extract<'a, 'f, V, E>(
    field: &'f str,
    expr: E,
) -> SQLExpr<'a, V, <V::DialectMarker as DialectTypes>::Double, E::Nullable, E::Aggregate>
where V: SQLParam + 'a, V::DialectMarker: PostgresDateTimeSupport, E: Expr<'a, V>, E::SQLType: Temporal, 'f: 'a,
Expand description

EXTRACT - extracts a component from a temporal expression (PostgreSQL/Standard SQL).

Returns a dialect-aware double type. Common fields: ‘year’, ‘month’, ‘day’, ‘hour’, ‘minute’, ‘second’, ‘dow’ (day of week), ‘doy’ (day of year), ‘epoch’ (Unix timestamp)

Preserves the nullability of the input expression.

§Example

use drizzle_core::expr::extract;

// SELECT EXTRACT(YEAR FROM users.created_at)
let year = extract("YEAR", users.created_at);