pub trait PgSortExpressionMethods: Sized {
    // Provided methods
    fn nulls_first(self) -> NullsFirst<Self> { ... }
    fn nulls_last(self) -> NullsLast<Self> { ... }
}
Available on crate feature postgres_backend only.
Expand description

PostgreSQL expression methods related to sorting.

This trait is only implemented for Asc and Desc. Although .asc is implicit if no order is given, you will need to call .asc() explicitly in order to call these methods.

Provided Methods§

source

fn nulls_first(self) -> NullsFirst<Self>

Specify that nulls should come before other values in this ordering.

Normally, nulls come last when sorting in ascending order and first when sorting in descending order.

§Example
diesel::insert_into(nullable_numbers)
    .values(&vec![
        nullable_number.eq(None),
        nullable_number.eq(Some(1)),
        nullable_number.eq(Some(2)),
    ])
    .execute(connection)?;

let asc_default_nulls = nullable_numbers.select(nullable_number)
    .order(nullable_number.asc())
    .load(connection)?;
assert_eq!(vec![Some(1), Some(2), None], asc_default_nulls);

let asc_nulls_first = nullable_numbers.select(nullable_number)
    .order(nullable_number.asc().nulls_first())
    .load(connection)?;
assert_eq!(vec![None, Some(1), Some(2)], asc_nulls_first);
source

fn nulls_last(self) -> NullsLast<Self>

Specify that nulls should come after other values in this ordering.

Normally, nulls come last when sorting in ascending order and first when sorting in descending order.

§Example
diesel::insert_into(nullable_numbers)
    .values(&vec![
        nullable_number.eq(None),
        nullable_number.eq(Some(1)),
        nullable_number.eq(Some(2)),
    ])
    .execute(connection)?;

let desc_default_nulls = nullable_numbers.select(nullable_number)
    .order(nullable_number.desc())
    .load(connection)?;
assert_eq!(vec![None, Some(2), Some(1)], desc_default_nulls);

let desc_nulls_last = nullable_numbers.select(nullable_number)
    .order(nullable_number.desc().nulls_last())
    .load(connection)?;
assert_eq!(vec![Some(2), Some(1), None], desc_nulls_last);

Object Safety§

This trait is not object safe.

Implementors§