lead_with_offset

Function lead_with_offset 

Source
pub fn lead_with_offset<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>, value, offset>(
    value: value,
    offset: offset,
) -> lead_with_offset<T, <value as AsExpression<T>>::Expression, <offset as AsExpression<Integer>>::Expression>
where value: AsExpression<T>, offset: AsExpression<Integer>,
Expand description

Value of argument from row leading current row within partition

Returns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, NULL is returned instead

This function must be used as window function. You need to call at least one of the methods WindowExpressionMethods from to use this function in your SELECT clause. It cannot be used outside of SELECT clauses.

For MySQL this function requires you to call .window_order()

let res = posts
    .select((
        title,
        user_id,
        lead_with_offset(id, 1)
            .partition_by(user_id)
            .window_order(user_id),
    ))
    .load::<(String, i32, Option<i32>)>(connection)?;
let expected = vec![
    ("My first post".to_owned(), 1, Some(2)),
    ("About Rust".into(), 1, None),
    ("My first post too".into(), 2, None),
];
assert_eq!(expected, res);