Skip to main content

diesel/expression/functions/
window_functions.rs

1#[cfg(doc)]
2use super::aggregate_expressions::WindowExpressionMethods;
3use crate::sql_types::helper::CombinedNullableValue;
4use crate::sql_types::{Integer, IntoNotNullable, IntoNullable, SingleValue, SqlType};
5use diesel_derives::declare_sql_function;
6
7#[doc = " Number of th current row within its partition"]
#[doc = ""]
#[doc =
" Returns the number of the current row within its partition, counting from 1."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select((title, user_id, row_number().partition_by(user_id)))"]
#[doc = "     .load::<(String, i32, i64)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 1),"]
#[doc = "     (\"About Rust\".into(), 1, 2),"]
#[doc = "     (\"My first post too\".into(), 2, 1),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn row_number() -> row_number where  { row_number_utils::row_number {} }
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`row_number()`](fn@row_number)"]
pub type row_number = row_number_utils::row_number<>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod row_number_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct row_number {}
    #[automatically_derived]
    impl ::core::fmt::Debug for row_number {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::write_str(f, "row_number")
        }
    }
    #[automatically_derived]
    #[doc(hidden)]
    unsafe impl ::core::clone::TrivialClone for row_number { }
    #[automatically_derived]
    impl ::core::clone::Clone for row_number {
        #[inline]
        fn clone(&self) -> Self { *self }
    }
    #[automatically_derived]
    impl ::core::marker::Copy for row_number { }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl diesel::query_builder::QueryId for row_number {
                type QueryId = row_number<>;
                const HAS_STATIC_QUERY_ID: bool = true;
                const IS_WINDOW_FUNCTION: bool = false;
            }
        };
    #[doc = "The return type of [`row_number()`](fn@row_number)"]
    pub type HelperType = row_number<>;
    impl Expression for row_number where  {
        type SqlType = BigInt;
    }
    impl<__DieselInternal> SelectableExpression<__DieselInternal> for
        row_number where Self: AppearsOnTable<__DieselInternal> {}
    impl<__DieselInternal> AppearsOnTable<__DieselInternal> for row_number
        where Self: Expression {}
    impl<__DieselInternal> FunctionFragment<__DieselInternal> for row_number
        where __DieselInternal: diesel::backend::Backend {
        const FUNCTION_NAME: &'static str = "row_number";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            Ok(())
        }
    }
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<row_number, __DieselInternal> for
        OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend {}
    impl IsWindowFunction for row_number {
        type ArgTypes = ();
    }
}
#[doc = " Rank of current row within its partition, with gaps"]
#[doc = ""]
#[doc = " Returns the rank of the current row, with gaps;"]
#[doc = " that is, the row_number of the first row in its peer group."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         rank().partition_by(user_id).window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, i64)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 1),"]
#[doc = "     (\"About Rust\".into(), 1, 1),"]
#[doc = "     (\"My first post too\".into(), 2, 1),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn rank() -> rank where  { rank_utils::rank {} }
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`rank()`](fn@rank)"]
pub type rank = rank_utils::rank<>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod rank_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct rank {}
    #[automatically_derived]
    impl ::core::fmt::Debug for rank {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::write_str(f, "rank")
        }
    }
    #[automatically_derived]
    #[doc(hidden)]
    unsafe impl ::core::clone::TrivialClone for rank { }
    #[automatically_derived]
    impl ::core::clone::Clone for rank {
        #[inline]
        fn clone(&self) -> Self { *self }
    }
    #[automatically_derived]
    impl ::core::marker::Copy for rank { }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl diesel::query_builder::QueryId for rank {
                type QueryId = rank<>;
                const HAS_STATIC_QUERY_ID: bool = true;
                const IS_WINDOW_FUNCTION: bool = false;
            }
        };
    #[doc = "The return type of [`rank()`](fn@rank)"]
    pub type HelperType = rank<>;
    impl Expression for rank where  {
        type SqlType = BigInt;
    }
    impl<__DieselInternal> SelectableExpression<__DieselInternal> for rank
        where Self: AppearsOnTable<__DieselInternal> {}
    impl<__DieselInternal> AppearsOnTable<__DieselInternal> for rank where
        Self: Expression {}
    impl<__DieselInternal> FunctionFragment<__DieselInternal> for rank where
        __DieselInternal: diesel::backend::Backend {
        const FUNCTION_NAME: &'static str = "rank";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            Ok(())
        }
    }
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<rank, __DieselInternal> for
        OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<rank, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<rank, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<__P, __O, __F> WindowFunctionFragment<rank, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<__P, __O, __F> WindowFunctionFragment<rank, diesel::mariadb::Mariadb>
        for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl IsWindowFunction for rank {
        type ArgTypes = ();
    }
}
#[doc = " Rank of current row within its partition, without gaps"]
#[doc = ""]
#[doc = " Returns the rank of the current row, without gaps;"]
#[doc = " this function effectively counts peer groups."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         dense_rank().partition_by(user_id).window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, i64)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 1),"]
#[doc = "     (\"About Rust\".into(), 1, 1),"]
#[doc = "     (\"My first post too\".into(), 2, 1),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn dense_rank() -> dense_rank where  { dense_rank_utils::dense_rank {} }
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`dense_rank()`](fn@dense_rank)"]
pub type dense_rank = dense_rank_utils::dense_rank<>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod dense_rank_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct dense_rank {}
    #[automatically_derived]
    impl ::core::fmt::Debug for dense_rank {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::write_str(f, "dense_rank")
        }
    }
    #[automatically_derived]
    #[doc(hidden)]
    unsafe impl ::core::clone::TrivialClone for dense_rank { }
    #[automatically_derived]
    impl ::core::clone::Clone for dense_rank {
        #[inline]
        fn clone(&self) -> Self { *self }
    }
    #[automatically_derived]
    impl ::core::marker::Copy for dense_rank { }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl diesel::query_builder::QueryId for dense_rank {
                type QueryId = dense_rank<>;
                const HAS_STATIC_QUERY_ID: bool = true;
                const IS_WINDOW_FUNCTION: bool = false;
            }
        };
    #[doc = "The return type of [`dense_rank()`](fn@dense_rank)"]
    pub type HelperType = dense_rank<>;
    impl Expression for dense_rank where  {
        type SqlType = BigInt;
    }
    impl<__DieselInternal> SelectableExpression<__DieselInternal> for
        dense_rank where Self: AppearsOnTable<__DieselInternal> {}
    impl<__DieselInternal> AppearsOnTable<__DieselInternal> for dense_rank
        where Self: Expression {}
    impl<__DieselInternal> FunctionFragment<__DieselInternal> for dense_rank
        where __DieselInternal: diesel::backend::Backend {
        const FUNCTION_NAME: &'static str = "dense_rank";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            Ok(())
        }
    }
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<dense_rank, __DieselInternal> for
        OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<dense_rank, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<dense_rank, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<__P, __O, __F>
        WindowFunctionFragment<dense_rank, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<__P, __O, __F>
        WindowFunctionFragment<dense_rank, diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl IsWindowFunction for dense_rank {
        type ArgTypes = ();
    }
}
#[doc = " Percentage rank value"]
#[doc = ""]
#[doc = " Returns the relative rank of the current row,"]
#[doc = " that is (rank - 1) / (total partition rows - 1)."]
#[doc = " The value thus ranges from 0 to 1 inclusive."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc =
"         percent_rank().partition_by(user_id).window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, f64)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 0.0),"]
#[doc = "     (\"About Rust\".into(), 1, 0.0),"]
#[doc = "     (\"My first post too\".into(), 2, 0.0),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn percent_rank() -> percent_rank where  {
    percent_rank_utils::percent_rank {}
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`percent_rank()`](fn@percent_rank)"]
pub type percent_rank = percent_rank_utils::percent_rank<>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod percent_rank_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct percent_rank {}
    #[automatically_derived]
    impl ::core::fmt::Debug for percent_rank {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::write_str(f, "percent_rank")
        }
    }
    #[automatically_derived]
    #[doc(hidden)]
    unsafe impl ::core::clone::TrivialClone for percent_rank { }
    #[automatically_derived]
    impl ::core::clone::Clone for percent_rank {
        #[inline]
        fn clone(&self) -> Self { *self }
    }
    #[automatically_derived]
    impl ::core::marker::Copy for percent_rank { }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl diesel::query_builder::QueryId for percent_rank {
                type QueryId = percent_rank<>;
                const HAS_STATIC_QUERY_ID: bool = true;
                const IS_WINDOW_FUNCTION: bool = false;
            }
        };
    #[doc = "The return type of [`percent_rank()`](fn@percent_rank)"]
    pub type HelperType = percent_rank<>;
    impl Expression for percent_rank where  {
        type SqlType = Double;
    }
    impl<__DieselInternal> SelectableExpression<__DieselInternal> for
        percent_rank where Self: AppearsOnTable<__DieselInternal> {}
    impl<__DieselInternal> AppearsOnTable<__DieselInternal> for percent_rank
        where Self: Expression {}
    impl<__DieselInternal> FunctionFragment<__DieselInternal> for percent_rank
        where __DieselInternal: diesel::backend::Backend {
        const FUNCTION_NAME: &'static str = "percent_rank";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            Ok(())
        }
    }
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<percent_rank, __DieselInternal> for
        OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<percent_rank, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<percent_rank, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<__P, __O, __F>
        WindowFunctionFragment<percent_rank, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<__P, __O, __F>
        WindowFunctionFragment<percent_rank, diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl IsWindowFunction for percent_rank {
        type ArgTypes = ();
    }
}
#[doc = " Cumulative distribution value"]
#[doc = ""]
#[doc = " Returns the cumulative distribution,"]
#[doc =
" that is (number of partition rows preceding or peers with current row) / (total partition rows)."]
#[doc = " The value thus ranges from 1/N to 1."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         cume_dist().partition_by(user_id).window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, f64)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 1.0),"]
#[doc = "     (\"About Rust\".into(), 1, 1.0),"]
#[doc = "     (\"My first post too\".into(), 2, 1.0),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn cume_dist() -> cume_dist where  { cume_dist_utils::cume_dist {} }
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`cume_dist()`](fn@cume_dist)"]
pub type cume_dist = cume_dist_utils::cume_dist<>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod cume_dist_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct cume_dist {}
    #[automatically_derived]
    impl ::core::fmt::Debug for cume_dist {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::write_str(f, "cume_dist")
        }
    }
    #[automatically_derived]
    #[doc(hidden)]
    unsafe impl ::core::clone::TrivialClone for cume_dist { }
    #[automatically_derived]
    impl ::core::clone::Clone for cume_dist {
        #[inline]
        fn clone(&self) -> Self { *self }
    }
    #[automatically_derived]
    impl ::core::marker::Copy for cume_dist { }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl diesel::query_builder::QueryId for cume_dist {
                type QueryId = cume_dist<>;
                const HAS_STATIC_QUERY_ID: bool = true;
                const IS_WINDOW_FUNCTION: bool = false;
            }
        };
    #[doc = "The return type of [`cume_dist()`](fn@cume_dist)"]
    pub type HelperType = cume_dist<>;
    impl Expression for cume_dist where  {
        type SqlType = Double;
    }
    impl<__DieselInternal> SelectableExpression<__DieselInternal> for
        cume_dist where Self: AppearsOnTable<__DieselInternal> {}
    impl<__DieselInternal> AppearsOnTable<__DieselInternal> for cume_dist
        where Self: Expression {}
    impl<__DieselInternal> FunctionFragment<__DieselInternal> for cume_dist
        where __DieselInternal: diesel::backend::Backend {
        const FUNCTION_NAME: &'static str = "cume_dist";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            Ok(())
        }
    }
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<cume_dist, __DieselInternal> for
        OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<cume_dist, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<__P, __O, __F, __DieselInternal>
        WindowFunctionFragment<cume_dist, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<__P, __O, __F>
        WindowFunctionFragment<cume_dist, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<__P, __O, __F>
        WindowFunctionFragment<cume_dist, diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl IsWindowFunction for cume_dist {
        type ArgTypes = ();
    }
}
#[doc = " Bucket number of current row within its partition"]
#[doc = ""]
#[doc = " Returns an integer ranging from 1 to the argument value,"]
#[doc = " dividing the partition as equally as possible."]
#[doc = ""]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select((title, user_id, ntile(2).partition_by(user_id)))"]
#[doc = "     .load::<(String, i32, i32)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 1),"]
#[doc = "     (\"About Rust\".into(), 1, 2),"]
#[doc = "     (\"My first post too\".into(), 2, 1),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn ntile<num_buckets>(num_buckets: num_buckets) -> ntile<num_buckets>
    where num_buckets: diesel::expression::AsExpression<Integer> {
    ntile_utils::ntile { num_buckets: num_buckets.as_expression() }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`ntile()`](fn@ntile)"]
pub type ntile<num_buckets> =
    ntile_utils::ntile<<num_buckets as
    diesel::expression::AsExpression<Integer>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod ntile_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct ntile<num_buckets> {
        pub(in super) num_buckets: num_buckets,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<num_buckets, __Rhs> ::core::ops::Add<__Rhs> for
                ntile<num_buckets> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<num_buckets, __Rhs> ::core::ops::Sub<__Rhs> for
                ntile<num_buckets> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<num_buckets, __Rhs> ::core::ops::Mul<__Rhs> for
                ntile<num_buckets> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<num_buckets, __Rhs> ::core::ops::Div<__Rhs> for
                ntile<num_buckets> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<num_buckets: ::core::fmt::Debug> ::core::fmt::Debug for
        ntile<num_buckets> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field1_finish(f,
                "ntile num_buckets", &&self.num_buckets)
        }
    }
    #[automatically_derived]
    impl<num_buckets: ::core::clone::Clone> ::core::clone::Clone for
        ntile<num_buckets> {
        #[inline]
        fn clone(&self) -> Self {
            ntile {
                num_buckets: ::core::clone::Clone::clone(&self.num_buckets),
            }
        }
    }
    #[automatically_derived]
    impl<num_buckets: ::core::marker::Copy> ::core::marker::Copy for
        ntile<num_buckets> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<num_buckets: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for ntile<num_buckets> {
                type QueryId =
                    ntile<<num_buckets as
                    diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <num_buckets as
                            diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <num_buckets as
                            diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`ntile()`](fn@ntile)"]
    pub type HelperType<num_buckets> =
        ntile<<num_buckets as AsExpression<Integer>>::Expression>;
    impl<num_buckets> Expression for ntile<num_buckets> where
        (num_buckets): Expression {
        type SqlType = Integer;
    }
    impl<num_buckets, __DieselInternal> SelectableExpression<__DieselInternal>
        for ntile<num_buckets> where
        num_buckets: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<num_buckets, __DieselInternal> AppearsOnTable<__DieselInternal> for
        ntile<num_buckets> where
        num_buckets: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<num_buckets, __DieselInternal> FunctionFragment<__DieselInternal> for
        ntile<num_buckets> where __DieselInternal: diesel::backend::Backend,
        num_buckets: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "ntile";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.num_buckets.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.num_buckets.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<num_buckets, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<ntile<num_buckets>, __DieselInternal> for
        OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend {}
    impl<num_buckets> IsWindowFunction for ntile<num_buckets> {
        type ArgTypes = (num_buckets,);
    }
}
#[doc = " Value of argument from row lagging current row within partition"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is one row before the current"]
#[doc =
" row within the partition. If there is no such row, NULL is returned instead."]
#[doc = ""]
#[doc =
" See [`lag_with_offset`] and [`lag_with_offset_and_default`] for variants with configurable offset"]
#[doc = " and default values."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         lag(id).partition_by(user_id).window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, None),"]
#[doc = "     (\"About Rust\".into(), 1, Some(1)),"]
#[doc = "     (\"My first post too\".into(), 2, None),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn lag<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
    value>(value: value) -> lag<T, value> where
    value: diesel::expression::AsExpression<T> {
    lag_utils::lag {
        value: value.as_expression(),
        T: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`lag()`](fn@lag)"]
pub type lag<T, value> =
    lag_utils::lag<T,
    <value as diesel::expression::AsExpression<T>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod lag_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct lag<T, value> {
        pub(in super) value: value,
        pub(in super) T: ::core::marker::PhantomData<T>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, value, __Rhs> ::core::ops::Add<__Rhs> for lag<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Sub<__Rhs> for lag<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Mul<__Rhs> for lag<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Div<__Rhs> for lag<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, value: ::core::fmt::Debug> ::core::fmt::Debug
        for lag<T, value> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field2_finish(f,
                "lag value T", &self.value, &&self.T)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, value: ::core::clone::Clone>
        ::core::clone::Clone for lag<T, value> {
        #[inline]
        fn clone(&self) -> Self {
            lag {
                value: ::core::clone::Clone::clone(&self.value),
                T: ::core::clone::Clone::clone(&self.T),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, value: ::core::marker::Copy>
        ::core::marker::Copy for lag<T, value> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for lag<T, value> {
                type QueryId =
                    lag<<T as diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                            &&
                            <value as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <value as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`lag()`](fn@lag)"]
    pub type HelperType<T, value> =
        lag<T, <value as AsExpression<T>>::Expression>;
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value> Expression for lag<T, value> where (value): Expression {
        type SqlType = T::Nullable;
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __DieselInternal> SelectableExpression<__DieselInternal> for
        lag<T, value> where value: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __DieselInternal> AppearsOnTable<__DieselInternal> for
        lag<T, value> where value: AppearsOnTable<__DieselInternal>,
        Self: Expression {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __DieselInternal> FunctionFragment<__DieselInternal> for
        lag<T, value> where __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "lag";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lag<T, value>, __DieselInternal> for
        OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<lag<T, value>, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lag<T, value>, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F>
        WindowFunctionFragment<lag<T, value>, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F>
        WindowFunctionFragment<lag<T, value>, diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value> IsWindowFunction for lag<T, value> {
        type ArgTypes = (value,);
    }
}
#[doc = " Value of argument from row lagging current row within partition"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is offset rows before the current"]
#[doc =
" row within the partition; If there is no such row, NULL is returned instead."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         lag_with_offset(id, 1)"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, None),"]
#[doc = "     (\"About Rust\".into(), 1, Some(1)),"]
#[doc = "     (\"My first post too\".into(), 2, None),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[doc(alias = "lag")]
#[allow(non_camel_case_types)]
pub fn lag_with_offset<T: SqlType + SingleValue +
    IntoNullable<Nullable : SingleValue>, value,
    offset>(value: value, offset: offset) -> lag_with_offset<T, value, offset>
    where value: diesel::expression::AsExpression<T>,
    offset: diesel::expression::AsExpression<Integer> {
    lag_with_offset_utils::lag_with_offset {
        value: value.as_expression(),
        offset: offset.as_expression(),
        T: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`lag_with_offset()`](fn@lag_with_offset)"]
pub type lag_with_offset<T, value, offset> =
    lag_with_offset_utils::lag_with_offset<T,
    <value as diesel::expression::AsExpression<T>>::Expression,
    <offset as diesel::expression::AsExpression<Integer>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod lag_with_offset_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct lag_with_offset<T, value, offset> {
        pub(in super) value: value,
        pub(in super) offset: offset,
        pub(in super) T: ::core::marker::PhantomData<T>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, value, offset, __Rhs> ::core::ops::Add<__Rhs> for
                lag_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, value, offset, __Rhs> ::core::ops::Sub<__Rhs> for
                lag_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, value, offset, __Rhs> ::core::ops::Mul<__Rhs> for
                lag_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, value, offset, __Rhs> ::core::ops::Div<__Rhs> for
                lag_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, value: ::core::fmt::Debug,
        offset: ::core::fmt::Debug> ::core::fmt::Debug for
        lag_with_offset<T, value, offset> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field3_finish(f,
                "lag_with_offset value offset T", &self.value, &self.offset,
                &&self.T)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, value: ::core::clone::Clone,
        offset: ::core::clone::Clone> ::core::clone::Clone for
        lag_with_offset<T, value, offset> {
        #[inline]
        fn clone(&self) -> Self {
            lag_with_offset {
                value: ::core::clone::Clone::clone(&self.value),
                offset: ::core::clone::Clone::clone(&self.offset),
                T: ::core::clone::Clone::clone(&self.T),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, value: ::core::marker::Copy,
        offset: ::core::marker::Copy> ::core::marker::Copy for
        lag_with_offset<T, value, offset> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId,
                offset: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for
                lag_with_offset<T, value, offset> {
                type QueryId =
                    lag_with_offset<<T as
                    diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId,
                    <offset as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                                &&
                                <value as
                                    diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                            <offset as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                                <value as
                                    diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <offset as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`lag_with_offset()`](fn@lag_with_offset)"]
    pub type HelperType<T, value, offset> =
        lag_with_offset<T, <value as AsExpression<T>>::Expression,
        <offset as AsExpression<Integer>>::Expression>;
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset> Expression for lag_with_offset<T, value, offset> where
        (value, offset): Expression {
        type SqlType = T::Nullable;
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __DieselInternal>
        SelectableExpression<__DieselInternal> for
        lag_with_offset<T, value, offset> where
        value: SelectableExpression<__DieselInternal>,
        offset: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __DieselInternal> AppearsOnTable<__DieselInternal> for
        lag_with_offset<T, value, offset> where
        value: AppearsOnTable<__DieselInternal>,
        offset: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __DieselInternal> FunctionFragment<__DieselInternal>
        for lag_with_offset<T, value, offset> where
        __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal>,
        offset: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "lag";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            if !self.offset.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.offset.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lag_with_offset<T, value, offset>,
        __DieselInternal> for OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<lag_with_offset<T, value, offset>,
        __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lag_with_offset<T, value, offset>,
        __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F>
        WindowFunctionFragment<lag_with_offset<T, value, offset>,
        diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F>
        WindowFunctionFragment<lag_with_offset<T, value, offset>,
        diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset> IsWindowFunction for lag_with_offset<T, value, offset>
        {
        type ArgTypes = (value, offset);
    }
}
#[doc = " Value of argument from row lagging current row within partition"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is offset rows before the current"]
#[doc =
" row within the partition; if there is no such row, instead returns default"]
#[doc = " (which must be of a type compatible with value)."]
#[doc =
" Both offset and default are evaluated with respect to the current row."]
#[doc = " If omitted, offset defaults to 1 and default to NULL."]
#[doc = ""]
#[doc =
" This function returns a nullable value if either the value or the default expression are"]
#[doc = " nullable."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(not(feature = \"mariadb\"))]"]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(all(not(miri), not(feature = \"mariadb\")))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     use diesel::sql_types::{Integer, Nullable};"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         lag_with_offset_and_default(id, 1, user_id)"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, i32)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 1),"]
#[doc = "     (\"About Rust\".into(), 1, 1),"]
#[doc = "     (\"My first post too\".into(), 2, 2),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = ""]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc =
"         lag_with_offset_and_default(None::<i32>.into_sql::<Nullable<Integer>>(), 1, user_id)"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, Some(1)),"]
#[doc = "     (\"About Rust\".into(), 1, None),"]
#[doc = "     (\"My first post too\".into(), 2, Some(2)),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = ""]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc =
"         lag_with_offset_and_default(id, 1, None::<i32>.into_sql::<Nullable<Integer>>())"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, None),"]
#[doc = "     (\"About Rust\".into(), 1, Some(1)),"]
#[doc = "     (\"My first post too\".into(), 2, None),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " # #[cfg(feature = \"mariadb\")]"]
#[doc = " # fn main() {}"]
#[doc = " ```"]
#[doc(alias = "lag")]
#[allow(non_camel_case_types)]
pub fn lag_with_offset_and_default<T: SqlType + SingleValue +
    IntoNotNullable<NotNullable : self::private::SameType<T2::NotNullable>> +
    CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
    IntoNotNullable, value, offset,
    default>(value: value, offset: offset, default: default)
    -> lag_with_offset_and_default<T, T2, value, offset, default> where
    value: diesel::expression::AsExpression<T>,
    offset: diesel::expression::AsExpression<Integer>,
    default: diesel::expression::AsExpression<T2> {
    lag_with_offset_and_default_utils::lag_with_offset_and_default {
        value: value.as_expression(),
        offset: offset.as_expression(),
        default: default.as_expression(),
        T: ::core::marker::PhantomData,
        T2: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc =
"The return type of [`lag_with_offset_and_default()`](fn@lag_with_offset_and_default)"]
pub type lag_with_offset_and_default<T, T2, value, offset, default> =
    lag_with_offset_and_default_utils::lag_with_offset_and_default<T, T2,
    <value as diesel::expression::AsExpression<T>>::Expression,
    <offset as diesel::expression::AsExpression<Integer>>::Expression,
    <default as diesel::expression::AsExpression<T2>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod lag_with_offset_and_default_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct lag_with_offset_and_default<T, T2, value, offset, default> {
        pub(in super) value: value,
        pub(in super) offset: offset,
        pub(in super) default: default,
        pub(in super) T: ::core::marker::PhantomData<T>,
        pub(in super) T2: ::core::marker::PhantomData<T2>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Add<__Rhs>
                for lag_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Sub<__Rhs>
                for lag_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Mul<__Rhs>
                for lag_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Div<__Rhs>
                for lag_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, T2: ::core::fmt::Debug,
        value: ::core::fmt::Debug, offset: ::core::fmt::Debug,
        default: ::core::fmt::Debug> ::core::fmt::Debug for
        lag_with_offset_and_default<T, T2, value, offset, default> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field5_finish(f,
                "lag_with_offset_and_default value offset default T T2",
                &self.value, &self.offset, &self.default, &self.T, &&self.T2)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, T2: ::core::clone::Clone,
        value: ::core::clone::Clone, offset: ::core::clone::Clone,
        default: ::core::clone::Clone> ::core::clone::Clone for
        lag_with_offset_and_default<T, T2, value, offset, default> {
        #[inline]
        fn clone(&self) -> Self {
            lag_with_offset_and_default {
                value: ::core::clone::Clone::clone(&self.value),
                offset: ::core::clone::Clone::clone(&self.offset),
                default: ::core::clone::Clone::clone(&self.default),
                T: ::core::clone::Clone::clone(&self.T),
                T2: ::core::clone::Clone::clone(&self.T2),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, T2: ::core::marker::Copy,
        value: ::core::marker::Copy, offset: ::core::marker::Copy,
        default: ::core::marker::Copy> ::core::marker::Copy for
        lag_with_offset_and_default<T, T2, value, offset, default> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                T2: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId,
                offset: diesel::query_builder::QueryId,
                default: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for
                lag_with_offset_and_default<T, T2, value, offset, default> {
                type QueryId =
                    lag_with_offset_and_default<<T as
                    diesel::query_builder::QueryId>::QueryId,
                    <T2 as diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId,
                    <offset as diesel::query_builder::QueryId>::QueryId,
                    <default as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                                        &&
                                        <T2 as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                                    &&
                                    <value as
                                        diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                                <offset as
                                    diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                            <default as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                                        <T2 as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION
                                    ||
                                    <value as
                                        diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                                <offset as
                                    diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <default as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc =
    "The return type of [`lag_with_offset_and_default()`](fn@lag_with_offset_and_default)"]
    pub type HelperType<T, T2, value, offset, default> =
        lag_with_offset_and_default<T, T2,
        <value as AsExpression<T>>::Expression,
        <offset as AsExpression<Integer>>::Expression,
        <default as AsExpression<T2>>::Expression>;
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default> Expression for
        lag_with_offset_and_default<T, T2, value, offset, default> where
        (value, offset, default): Expression {
        type SqlType = T::Out;
    }
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __DieselInternal>
        SelectableExpression<__DieselInternal> for
        lag_with_offset_and_default<T, T2, value, offset, default> where
        value: SelectableExpression<__DieselInternal>,
        offset: SelectableExpression<__DieselInternal>,
        default: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __DieselInternal>
        AppearsOnTable<__DieselInternal> for
        lag_with_offset_and_default<T, T2, value, offset, default> where
        value: AppearsOnTable<__DieselInternal>,
        offset: AppearsOnTable<__DieselInternal>,
        default: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __DieselInternal>
        FunctionFragment<__DieselInternal> for
        lag_with_offset_and_default<T, T2, value, offset, default> where
        __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal>,
        offset: QueryFragment<__DieselInternal>,
        default: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "lag";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            if !self.offset.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.offset.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            if !self.default.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.default.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F,
        __DieselInternal>
        WindowFunctionFragment<lag_with_offset_and_default<T, T2, value,
        offset, default>, __DieselInternal> for OverClause<__P, __O, __F>
        where
        Self: WindowFunctionFragment<lag_with_offset_and_default<T, T2, value,
        offset, default>, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F,
        __DieselInternal>
        WindowFunctionFragment<lag_with_offset_and_default<T, T2, value,
        offset, default>, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F>
        WindowFunctionFragment<lag_with_offset_and_default<T, T2, value,
        offset, default>, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F>
        WindowFunctionFragment<lag_with_offset_and_default<T, T2, value,
        offset, default>, diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default> IsWindowFunction for
        lag_with_offset_and_default<T, T2, value, offset, default> {
        type ArgTypes = (value, offset, default);
    }
}
#[doc = " Value of argument from row leading current row within partition"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is offset rows after the current"]
#[doc = " row within the partition; if there is no such row,"]
#[doc = " `NULL` will be returned instead."]
#[doc = ""]
#[doc =
" See [`lead_with_offset`] and [`lead_with_offset_and_default`] for variants with configurable offset"]
#[doc = " and default values."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         lead(id).partition_by(user_id).window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, Some(2)),"]
#[doc = "     (\"About Rust\".into(), 1, None),"]
#[doc = "     (\"My first post too\".into(), 2, None),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn lead<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
    value>(value: value) -> lead<T, value> where
    value: diesel::expression::AsExpression<T> {
    lead_utils::lead {
        value: value.as_expression(),
        T: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`lead()`](fn@lead)"]
pub type lead<T, value> =
    lead_utils::lead<T,
    <value as diesel::expression::AsExpression<T>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod lead_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct lead<T, value> {
        pub(in super) value: value,
        pub(in super) T: ::core::marker::PhantomData<T>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, value, __Rhs> ::core::ops::Add<__Rhs> for lead<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Sub<__Rhs> for lead<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Mul<__Rhs> for lead<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Div<__Rhs> for lead<T, value>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, value: ::core::fmt::Debug> ::core::fmt::Debug
        for lead<T, value> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field2_finish(f,
                "lead value T", &self.value, &&self.T)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, value: ::core::clone::Clone>
        ::core::clone::Clone for lead<T, value> {
        #[inline]
        fn clone(&self) -> Self {
            lead {
                value: ::core::clone::Clone::clone(&self.value),
                T: ::core::clone::Clone::clone(&self.T),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, value: ::core::marker::Copy>
        ::core::marker::Copy for lead<T, value> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for lead<T, value> {
                type QueryId =
                    lead<<T as diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                            &&
                            <value as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <value as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`lead()`](fn@lead)"]
    pub type HelperType<T, value> =
        lead<T, <value as AsExpression<T>>::Expression>;
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value> Expression for lead<T, value> where (value): Expression {
        type SqlType = T::Nullable;
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __DieselInternal> SelectableExpression<__DieselInternal> for
        lead<T, value> where value: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __DieselInternal> AppearsOnTable<__DieselInternal> for
        lead<T, value> where value: AppearsOnTable<__DieselInternal>,
        Self: Expression {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __DieselInternal> FunctionFragment<__DieselInternal> for
        lead<T, value> where __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "lead";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lead<T, value>, __DieselInternal> for
        OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<lead<T, value>, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lead<T, value>, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F>
        WindowFunctionFragment<lead<T, value>, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, __P, __O, __F>
        WindowFunctionFragment<lead<T, value>, diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value> IsWindowFunction for lead<T, value> {
        type ArgTypes = (value,);
    }
}
#[doc = " Value of argument from row leading current row within partition"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is offset rows after the current"]
#[doc = " row within the partition; if there is no such row,"]
#[doc = " `NULL` is returned instead"]
#[doc = ""]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         lead_with_offset(id, 1)"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, Some(2)),"]
#[doc = "     (\"About Rust\".into(), 1, None),"]
#[doc = "     (\"My first post too\".into(), 2, None),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[doc(alias = "lead")]
#[allow(non_camel_case_types)]
pub fn lead_with_offset<T: SqlType + SingleValue +
    IntoNullable<Nullable : SingleValue>, value,
    offset>(value: value, offset: offset)
    -> lead_with_offset<T, value, offset> where
    value: diesel::expression::AsExpression<T>,
    offset: diesel::expression::AsExpression<Integer> {
    lead_with_offset_utils::lead_with_offset {
        value: value.as_expression(),
        offset: offset.as_expression(),
        T: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`lead_with_offset()`](fn@lead_with_offset)"]
pub type lead_with_offset<T, value, offset> =
    lead_with_offset_utils::lead_with_offset<T,
    <value as diesel::expression::AsExpression<T>>::Expression,
    <offset as diesel::expression::AsExpression<Integer>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod lead_with_offset_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct lead_with_offset<T, value, offset> {
        pub(in super) value: value,
        pub(in super) offset: offset,
        pub(in super) T: ::core::marker::PhantomData<T>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, value, offset, __Rhs> ::core::ops::Add<__Rhs> for
                lead_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, value, offset, __Rhs> ::core::ops::Sub<__Rhs> for
                lead_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, value, offset, __Rhs> ::core::ops::Mul<__Rhs> for
                lead_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, value, offset, __Rhs> ::core::ops::Div<__Rhs> for
                lead_with_offset<T, value, offset> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, value: ::core::fmt::Debug,
        offset: ::core::fmt::Debug> ::core::fmt::Debug for
        lead_with_offset<T, value, offset> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field3_finish(f,
                "lead_with_offset value offset T", &self.value, &self.offset,
                &&self.T)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, value: ::core::clone::Clone,
        offset: ::core::clone::Clone> ::core::clone::Clone for
        lead_with_offset<T, value, offset> {
        #[inline]
        fn clone(&self) -> Self {
            lead_with_offset {
                value: ::core::clone::Clone::clone(&self.value),
                offset: ::core::clone::Clone::clone(&self.offset),
                T: ::core::clone::Clone::clone(&self.T),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, value: ::core::marker::Copy,
        offset: ::core::marker::Copy> ::core::marker::Copy for
        lead_with_offset<T, value, offset> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId,
                offset: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for
                lead_with_offset<T, value, offset> {
                type QueryId =
                    lead_with_offset<<T as
                    diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId,
                    <offset as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                                &&
                                <value as
                                    diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                            <offset as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                                <value as
                                    diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <offset as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`lead_with_offset()`](fn@lead_with_offset)"]
    pub type HelperType<T, value, offset> =
        lead_with_offset<T, <value as AsExpression<T>>::Expression,
        <offset as AsExpression<Integer>>::Expression>;
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset> Expression for lead_with_offset<T, value, offset> where
        (value, offset): Expression {
        type SqlType = T::Nullable;
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __DieselInternal>
        SelectableExpression<__DieselInternal> for
        lead_with_offset<T, value, offset> where
        value: SelectableExpression<__DieselInternal>,
        offset: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __DieselInternal> AppearsOnTable<__DieselInternal> for
        lead_with_offset<T, value, offset> where
        value: AppearsOnTable<__DieselInternal>,
        offset: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __DieselInternal> FunctionFragment<__DieselInternal>
        for lead_with_offset<T, value, offset> where
        __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal>,
        offset: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "lead";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            if !self.offset.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.offset.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lead_with_offset<T, value, offset>,
        __DieselInternal> for OverClause<__P, __O, __F> where
        Self: WindowFunctionFragment<lead_with_offset<T, value, offset>,
        __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<lead_with_offset<T, value, offset>,
        __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F>
        WindowFunctionFragment<lead_with_offset<T, value, offset>,
        diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset, __P, __O, __F>
        WindowFunctionFragment<lead_with_offset<T, value, offset>,
        diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, offset> IsWindowFunction for lead_with_offset<T, value, offset>
        {
        type ArgTypes = (value, offset);
    }
}
#[doc = " Value of argument from row leading current row within partition"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is offset rows after the current"]
#[doc = " row within the partition; if there is no such row,"]
#[doc =
" instead returns default (which must be of a type compatible with value)."]
#[doc =
" Both offset and default are evaluated with respect to the current row."]
#[doc = " If omitted, offset defaults to 1 and default to NULL."]
#[doc = ""]
#[doc =
" This function returns a nullable value if either the value or the default expression are"]
#[doc = " nullable."]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc =
" For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())"]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(not(feature = \"mariadb\"))]"]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(all(not(miri), not(feature = \"mariadb\")))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     use diesel::sql_types::{Integer, Nullable};"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc = "         lead_with_offset_and_default(id, 1, user_id)"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, i32)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 2),"]
#[doc = "     (\"About Rust\".into(), 1, 1),"]
#[doc = "     (\"My first post too\".into(), 2, 2),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = ""]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc =
"         lead_with_offset_and_default(None::<i32>.into_sql::<Nullable<Integer>>(), 1, user_id)"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, None),"]
#[doc = "     (\"About Rust\".into(), 1, Some(1)),"]
#[doc = "     (\"My first post too\".into(), 2, Some(2)),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = ""]
#[doc = " let res = posts"]
#[doc = "     .select(("]
#[doc = "         title,"]
#[doc = "         user_id,"]
#[doc =
"         lead_with_offset_and_default(id, 1, None::<i32>.into_sql::<Nullable<Integer>>())"]
#[doc = "             .partition_by(user_id)"]
#[doc = "             .window_order(user_id),"]
#[doc = "     ))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, Some(2)),"]
#[doc = "     (\"About Rust\".into(), 1, None),"]
#[doc = "     (\"My first post too\".into(), 2, None),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " # #[cfg(feature = \"mariadb\")]"]
#[doc = " # fn main() {}"]
#[doc = " ```"]
#[doc(alias = "lead")]
#[allow(non_camel_case_types)]
pub fn lead_with_offset_and_default<T: SqlType + SingleValue +
    IntoNotNullable<NotNullable : self::private::SameType<T2::NotNullable>> +
    CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
    IntoNotNullable, value, offset,
    default>(value: value, offset: offset, default: default)
    -> lead_with_offset_and_default<T, T2, value, offset, default> where
    value: diesel::expression::AsExpression<T>,
    offset: diesel::expression::AsExpression<Integer>,
    default: diesel::expression::AsExpression<T2> {
    lead_with_offset_and_default_utils::lead_with_offset_and_default {
        value: value.as_expression(),
        offset: offset.as_expression(),
        default: default.as_expression(),
        T: ::core::marker::PhantomData,
        T2: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc =
"The return type of [`lead_with_offset_and_default()`](fn@lead_with_offset_and_default)"]
pub type lead_with_offset_and_default<T, T2, value, offset, default> =
    lead_with_offset_and_default_utils::lead_with_offset_and_default<T, T2,
    <value as diesel::expression::AsExpression<T>>::Expression,
    <offset as diesel::expression::AsExpression<Integer>>::Expression,
    <default as diesel::expression::AsExpression<T2>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod lead_with_offset_and_default_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct lead_with_offset_and_default<T, T2, value, offset, default> {
        pub(in super) value: value,
        pub(in super) offset: offset,
        pub(in super) default: default,
        pub(in super) T: ::core::marker::PhantomData<T>,
        pub(in super) T2: ::core::marker::PhantomData<T2>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Add<__Rhs>
                for
                lead_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Sub<__Rhs>
                for
                lead_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Mul<__Rhs>
                for
                lead_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, T2, value, offset, default, __Rhs> ::core::ops::Div<__Rhs>
                for
                lead_with_offset_and_default<T, T2, value, offset, default>
                where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, T2: ::core::fmt::Debug,
        value: ::core::fmt::Debug, offset: ::core::fmt::Debug,
        default: ::core::fmt::Debug> ::core::fmt::Debug for
        lead_with_offset_and_default<T, T2, value, offset, default> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field5_finish(f,
                "lead_with_offset_and_default value offset default T T2",
                &self.value, &self.offset, &self.default, &self.T, &&self.T2)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, T2: ::core::clone::Clone,
        value: ::core::clone::Clone, offset: ::core::clone::Clone,
        default: ::core::clone::Clone> ::core::clone::Clone for
        lead_with_offset_and_default<T, T2, value, offset, default> {
        #[inline]
        fn clone(&self) -> Self {
            lead_with_offset_and_default {
                value: ::core::clone::Clone::clone(&self.value),
                offset: ::core::clone::Clone::clone(&self.offset),
                default: ::core::clone::Clone::clone(&self.default),
                T: ::core::clone::Clone::clone(&self.T),
                T2: ::core::clone::Clone::clone(&self.T2),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, T2: ::core::marker::Copy,
        value: ::core::marker::Copy, offset: ::core::marker::Copy,
        default: ::core::marker::Copy> ::core::marker::Copy for
        lead_with_offset_and_default<T, T2, value, offset, default> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                T2: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId,
                offset: diesel::query_builder::QueryId,
                default: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for
                lead_with_offset_and_default<T, T2, value, offset, default> {
                type QueryId =
                    lead_with_offset_and_default<<T as
                    diesel::query_builder::QueryId>::QueryId,
                    <T2 as diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId,
                    <offset as diesel::query_builder::QueryId>::QueryId,
                    <default as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                                        &&
                                        <T2 as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                                    &&
                                    <value as
                                        diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                                <offset as
                                    diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                            <default as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                                        <T2 as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION
                                    ||
                                    <value as
                                        diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                                <offset as
                                    diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <default as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc =
    "The return type of [`lead_with_offset_and_default()`](fn@lead_with_offset_and_default)"]
    pub type HelperType<T, T2, value, offset, default> =
        lead_with_offset_and_default<T, T2,
        <value as AsExpression<T>>::Expression,
        <offset as AsExpression<Integer>>::Expression,
        <default as AsExpression<T2>>::Expression>;
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default> Expression for
        lead_with_offset_and_default<T, T2, value, offset, default> where
        (value, offset, default): Expression {
        type SqlType = T::Out;
    }
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __DieselInternal>
        SelectableExpression<__DieselInternal> for
        lead_with_offset_and_default<T, T2, value, offset, default> where
        value: SelectableExpression<__DieselInternal>,
        offset: SelectableExpression<__DieselInternal>,
        default: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __DieselInternal>
        AppearsOnTable<__DieselInternal> for
        lead_with_offset_and_default<T, T2, value, offset, default> where
        value: AppearsOnTable<__DieselInternal>,
        offset: AppearsOnTable<__DieselInternal>,
        default: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __DieselInternal>
        FunctionFragment<__DieselInternal> for
        lead_with_offset_and_default<T, T2, value, offset, default> where
        __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal>,
        offset: QueryFragment<__DieselInternal>,
        default: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "lead";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            if !self.offset.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.offset.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            if !self.default.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.default.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F,
        __DieselInternal>
        WindowFunctionFragment<lead_with_offset_and_default<T, T2, value,
        offset, default>, __DieselInternal> for OverClause<__P, __O, __F>
        where
        Self: WindowFunctionFragment<lead_with_offset_and_default<T, T2,
        value, offset, default>, __DieselInternal,
        <__DieselInternal as
        diesel::backend::SqlDialect>::BuiltInWindowFunctionRequireOrder>,
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F,
        __DieselInternal>
        WindowFunctionFragment<lead_with_offset_and_default<T, T2, value,
        offset, default>, __DieselInternal,
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        for OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend +
        diesel::backend::SqlDialect<BuiltInWindowFunctionRequireOrder =
        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired>
        {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F>
        WindowFunctionFragment<lead_with_offset_and_default<T, T2, value,
        offset, default>, diesel::mysql::Mysql> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default, __P, __O, __F>
        WindowFunctionFragment<lead_with_offset_and_default<T, T2, value,
        offset, default>, diesel::mariadb::Mariadb> for
        OverClause<__P, diesel::internal::sql_functions::Order<__O, true>,
        __F> where  {}
    impl<T: SqlType + SingleValue +
        IntoNotNullable<NotNullable
        : self::private::SameType<T2::NotNullable>> +
        CombinedNullableValue<T2, T::NotNullable>, T2: SqlType + SingleValue +
        IntoNotNullable, value, offset, default> IsWindowFunction for
        lead_with_offset_and_default<T, T2, value, offset, default> {
        type ArgTypes = (value, offset, default);
    }
}
#[doc = " Value of argument from first row of window frame"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is the first row of the window frame."]
#[doc = ""]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc =
"     .select((title, user_id, first_value(id).partition_by(user_id)))"]
#[doc = "     .load::<(String, i32, i32)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 1),"]
#[doc = "     (\"About Rust\".into(), 1, 1),"]
#[doc = "     (\"My first post too\".into(), 2, 3),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn first_value<T: SqlType + SingleValue, value>(value: value)
    -> first_value<T, value> where
    value: diesel::expression::AsExpression<T> {
    first_value_utils::first_value {
        value: value.as_expression(),
        T: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`first_value()`](fn@first_value)"]
pub type first_value<T, value> =
    first_value_utils::first_value<T,
    <value as diesel::expression::AsExpression<T>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod first_value_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct first_value<T, value> {
        pub(in super) value: value,
        pub(in super) T: ::core::marker::PhantomData<T>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, value, __Rhs> ::core::ops::Add<__Rhs> for
                first_value<T, value> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Sub<__Rhs> for
                first_value<T, value> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Mul<__Rhs> for
                first_value<T, value> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Div<__Rhs> for
                first_value<T, value> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, value: ::core::fmt::Debug> ::core::fmt::Debug
        for first_value<T, value> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field2_finish(f,
                "first_value value T", &self.value, &&self.T)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, value: ::core::clone::Clone>
        ::core::clone::Clone for first_value<T, value> {
        #[inline]
        fn clone(&self) -> Self {
            first_value {
                value: ::core::clone::Clone::clone(&self.value),
                T: ::core::clone::Clone::clone(&self.T),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, value: ::core::marker::Copy>
        ::core::marker::Copy for first_value<T, value> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for first_value<T, value> {
                type QueryId =
                    first_value<<T as diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                            &&
                            <value as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <value as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`first_value()`](fn@first_value)"]
    pub type HelperType<T, value> =
        first_value<T, <value as AsExpression<T>>::Expression>;
    impl<T: SqlType + SingleValue, value> Expression for first_value<T, value>
        where (value): Expression {
        type SqlType = T;
    }
    impl<T: SqlType + SingleValue, value, __DieselInternal>
        SelectableExpression<__DieselInternal> for first_value<T, value> where
        value: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue, value, __DieselInternal>
        AppearsOnTable<__DieselInternal> for first_value<T, value> where
        value: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<T: SqlType + SingleValue, value, __DieselInternal>
        FunctionFragment<__DieselInternal> for first_value<T, value> where
        __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "first_value";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue, value, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<first_value<T, value>, __DieselInternal> for
        OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue, value> IsWindowFunction for
        first_value<T, value> {
        type ArgTypes = (value,);
    }
}
#[doc = " Value of argument from last row of window frame"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is the last row of the window frame."]
#[doc = ""]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc =
"     .select((title, user_id, last_value(id).partition_by(user_id)))"]
#[doc = "     .load::<(String, i32, i32)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, 2),"]
#[doc = "     (\"About Rust\".into(), 1, 2),"]
#[doc = "     (\"My first post too\".into(), 2, 3),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn last_value<T: SqlType + SingleValue, value>(value: value)
    -> last_value<T, value> where value: diesel::expression::AsExpression<T> {
    last_value_utils::last_value {
        value: value.as_expression(),
        T: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`last_value()`](fn@last_value)"]
pub type last_value<T, value> =
    last_value_utils::last_value<T,
    <value as diesel::expression::AsExpression<T>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod last_value_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct last_value<T, value> {
        pub(in super) value: value,
        pub(in super) T: ::core::marker::PhantomData<T>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, value, __Rhs> ::core::ops::Add<__Rhs> for
                last_value<T, value> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Sub<__Rhs> for
                last_value<T, value> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Mul<__Rhs> for
                last_value<T, value> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, value, __Rhs> ::core::ops::Div<__Rhs> for
                last_value<T, value> where Self: Expression, Self: Expression,
                <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, value: ::core::fmt::Debug> ::core::fmt::Debug
        for last_value<T, value> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field2_finish(f,
                "last_value value T", &self.value, &&self.T)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, value: ::core::clone::Clone>
        ::core::clone::Clone for last_value<T, value> {
        #[inline]
        fn clone(&self) -> Self {
            last_value {
                value: ::core::clone::Clone::clone(&self.value),
                T: ::core::clone::Clone::clone(&self.T),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, value: ::core::marker::Copy>
        ::core::marker::Copy for last_value<T, value> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for last_value<T, value> {
                type QueryId =
                    last_value<<T as diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                            &&
                            <value as
                                diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                        true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <value as
                                diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`last_value()`](fn@last_value)"]
    pub type HelperType<T, value> =
        last_value<T, <value as AsExpression<T>>::Expression>;
    impl<T: SqlType + SingleValue, value> Expression for last_value<T, value>
        where (value): Expression {
        type SqlType = T;
    }
    impl<T: SqlType + SingleValue, value, __DieselInternal>
        SelectableExpression<__DieselInternal> for last_value<T, value> where
        value: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue, value, __DieselInternal>
        AppearsOnTable<__DieselInternal> for last_value<T, value> where
        value: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<T: SqlType + SingleValue, value, __DieselInternal>
        FunctionFragment<__DieselInternal> for last_value<T, value> where
        __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "last_value";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue, value, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<last_value<T, value>, __DieselInternal> for
        OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue, value> IsWindowFunction for
        last_value<T, value> {
        type ArgTypes = (value,);
    }
}
#[doc = " Value of argument from N-th row of window frame"]
#[doc = ""]
#[doc =
" Returns value evaluated at the row that is the n\'th row of the window frame (counting from 1);"]
#[doc = " returns NULL if there is no such row."]
#[doc = ""]
#[doc = ""]
#[doc =
" This function must be used as window function. You need to call at least one"]
#[doc =
" of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`"]
#[doc = " clause. It cannot be used outside of `SELECT` clauses."]
#[doc = ""]
#[doc = " ```"]
#[doc = " # include!(\"../../doctest_setup.rs\");"]
#[doc = " # use diesel::dsl::*;"]
#[doc = " #"]
#[doc =
" # // Reading the query result requires reading memory allocated by the"]
#[doc =
" # // native sqlite library, which miri cannot track provenance for."]
#[doc = " # #[cfg(miri)]"]
#[doc = " # fn main() {}"]
#[doc = " # #[cfg(not(miri))]"]
#[doc = " # fn main() -> QueryResult<()> {"]
#[doc = " #     use schema::posts::dsl::*;"]
#[doc = " #     let connection = &mut establish_connection();"]
#[doc = " let res = posts"]
#[doc =
"     .select((title, user_id, nth_value(id, 2).partition_by(user_id)))"]
#[doc = "     .load::<(String, i32, Option<i32>)>(connection)?;"]
#[doc = " let expected = vec!["]
#[doc = "     (\"My first post\".to_owned(), 1, Some(2)),"]
#[doc = "     (\"About Rust\".into(), 1, Some(2)),"]
#[doc = "     (\"My first post too\".into(), 2, None),"]
#[doc = " ];"]
#[doc = " assert_eq!(expected, res);"]
#[doc = " # Ok(())"]
#[doc = " # }"]
#[doc = " ```"]
#[allow(non_camel_case_types)]
pub fn nth_value<T: SqlType + SingleValue +
    IntoNullable<Nullable : SingleValue>, value, n>(value: value, n: n)
    -> nth_value<T, value, n> where
    value: diesel::expression::AsExpression<T>,
    n: diesel::expression::AsExpression<Integer> {
    nth_value_utils::nth_value {
        value: value.as_expression(),
        n: n.as_expression(),
        T: ::core::marker::PhantomData,
    }
}
#[allow(non_camel_case_types, non_snake_case)]
#[doc = "The return type of [`nth_value()`](fn@nth_value)"]
pub type nth_value<T, value, n> =
    nth_value_utils::nth_value<T,
    <value as diesel::expression::AsExpression<T>>::Expression,
    <n as diesel::expression::AsExpression<Integer>>::Expression>;
#[doc(hidden)]
#[allow(non_camel_case_types, non_snake_case, unused_imports)]
pub(crate) mod nth_value_utils {
    use diesel::{self, QueryResult};
    use diesel::expression::{
        AsExpression, Expression, SelectableExpression, AppearsOnTable,
        ValidGrouping,
    };
    use diesel::query_builder::{QueryFragment, AstPass};
    use diesel::sql_types::*;
    use diesel::internal::sql_functions::*;
    use super::*;
    pub struct nth_value<T, value, n> {
        pub(in super) value: value,
        pub(in super) n: n,
        pub(in super) T: ::core::marker::PhantomData<T>,
    }
    const _: () =
        {
            use diesel;
            use diesel::internal::derives::numeric_ops as ops;
            use diesel::expression::{Expression, AsExpression};
            use diesel::sql_types::ops::{Add, Sub, Mul, Div};
            use diesel::sql_types::{SqlType, SingleValue};
            impl<T, value, n, __Rhs> ::core::ops::Add<__Rhs> for
                nth_value<T, value, n> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Add,
                <<Self as Expression>::SqlType as Add>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Add>::Rhs> {
                type Output = ops::Add<Self, __Rhs::Expression>;
                fn add(self, rhs: __Rhs) -> Self::Output {
                    ops::Add::new(self, rhs.as_expression())
                }
            }
            impl<T, value, n, __Rhs> ::core::ops::Sub<__Rhs> for
                nth_value<T, value, n> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Sub,
                <<Self as Expression>::SqlType as Sub>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Sub>::Rhs> {
                type Output = ops::Sub<Self, __Rhs::Expression>;
                fn sub(self, rhs: __Rhs) -> Self::Output {
                    ops::Sub::new(self, rhs.as_expression())
                }
            }
            impl<T, value, n, __Rhs> ::core::ops::Mul<__Rhs> for
                nth_value<T, value, n> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Mul,
                <<Self as Expression>::SqlType as Mul>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Mul>::Rhs> {
                type Output = ops::Mul<Self, __Rhs::Expression>;
                fn mul(self, rhs: __Rhs) -> Self::Output {
                    ops::Mul::new(self, rhs.as_expression())
                }
            }
            impl<T, value, n, __Rhs> ::core::ops::Div<__Rhs> for
                nth_value<T, value, n> where Self: Expression,
                Self: Expression, <Self as Expression>::SqlType: Div,
                <<Self as Expression>::SqlType as Div>::Rhs: SqlType +
                SingleValue,
                __Rhs: AsExpression<<<Self as Expression>::SqlType as
                Div>::Rhs> {
                type Output = ops::Div<Self, __Rhs::Expression>;
                fn div(self, rhs: __Rhs) -> Self::Output {
                    ops::Div::new(self, rhs.as_expression())
                }
            }
        };
    #[automatically_derived]
    impl<T: ::core::fmt::Debug, value: ::core::fmt::Debug,
        n: ::core::fmt::Debug> ::core::fmt::Debug for nth_value<T, value, n> {
        #[inline]
        fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
            ::core::fmt::Formatter::debug_struct_field3_finish(f,
                "nth_value value n T", &self.value, &self.n, &&self.T)
        }
    }
    #[automatically_derived]
    impl<T: ::core::clone::Clone, value: ::core::clone::Clone,
        n: ::core::clone::Clone> ::core::clone::Clone for
        nth_value<T, value, n> {
        #[inline]
        fn clone(&self) -> Self {
            nth_value {
                value: ::core::clone::Clone::clone(&self.value),
                n: ::core::clone::Clone::clone(&self.n),
                T: ::core::clone::Clone::clone(&self.T),
            }
        }
    }
    #[automatically_derived]
    impl<T: ::core::marker::Copy, value: ::core::marker::Copy,
        n: ::core::marker::Copy> ::core::marker::Copy for
        nth_value<T, value, n> {
    }
    const _: () =
        {
            use diesel;
            #[allow(non_camel_case_types)]
            impl<T: diesel::query_builder::QueryId,
                value: diesel::query_builder::QueryId,
                n: diesel::query_builder::QueryId>
                diesel::query_builder::QueryId for nth_value<T, value, n> {
                type QueryId =
                    nth_value<<T as diesel::query_builder::QueryId>::QueryId,
                    <value as diesel::query_builder::QueryId>::QueryId,
                    <n as diesel::query_builder::QueryId>::QueryId>;
                const HAS_STATIC_QUERY_ID: bool =
                    <T as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                                &&
                                <value as
                                    diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID &&
                            <n as diesel::query_builder::QueryId>::HAS_STATIC_QUERY_ID
                        && true;
                const IS_WINDOW_FUNCTION: bool =
                    <T as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                                <value as
                                    diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                            <n as diesel::query_builder::QueryId>::IS_WINDOW_FUNCTION ||
                        false;
            }
        };
    #[doc = "The return type of [`nth_value()`](fn@nth_value)"]
    pub type HelperType<T, value, n> =
        nth_value<T, <value as AsExpression<T>>::Expression,
        <n as AsExpression<Integer>>::Expression>;
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, n> Expression for nth_value<T, value, n> where
        (value, n): Expression {
        type SqlType = T::Nullable;
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, n, __DieselInternal> SelectableExpression<__DieselInternal> for
        nth_value<T, value, n> where
        value: SelectableExpression<__DieselInternal>,
        n: SelectableExpression<__DieselInternal>,
        Self: AppearsOnTable<__DieselInternal> {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, n, __DieselInternal> AppearsOnTable<__DieselInternal> for
        nth_value<T, value, n> where value: AppearsOnTable<__DieselInternal>,
        n: AppearsOnTable<__DieselInternal>, Self: Expression {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, n, __DieselInternal> FunctionFragment<__DieselInternal> for
        nth_value<T, value, n> where
        __DieselInternal: diesel::backend::Backend,
        value: QueryFragment<__DieselInternal>,
        n: QueryFragment<__DieselInternal> {
        const FUNCTION_NAME: &'static str = "nth_value";
        #[allow(unused_assignments)]
        fn walk_arguments<'__b>(&'__b self,
            mut out: AstPass<'_, '__b, __DieselInternal>) -> QueryResult<()> {
            let mut needs_comma = false;
            if !self.value.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.value.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            if !self.n.is_noop(out.backend())? {
                if needs_comma { out.push_sql(", "); }
                self.n.walk_ast(out.reborrow())?;
                needs_comma = true;
            }
            Ok(())
        }
    }
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, n, __P, __O, __F, __DieselInternal>
        WindowFunctionFragment<nth_value<T, value, n>, __DieselInternal> for
        OverClause<__P, __O, __F> where
        __DieselInternal: diesel::backend::Backend {}
    impl<T: SqlType + SingleValue + IntoNullable<Nullable : SingleValue>,
        value, n> IsWindowFunction for nth_value<T, value, n> {
        type ArgTypes = (value, n);
    }
}#[declare_sql_function]
8extern "SQL" {
9
10    /// Number of th current row within its partition
11    ///
12    /// Returns the number of the current row within its partition, counting from 1.
13    ///
14    /// This function must be used as window function. You need to call at least one
15    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
16    /// clause. It cannot be used outside of `SELECT` clauses.
17    ///
18    /// ```
19    /// # include!("../../doctest_setup.rs");
20    /// # use diesel::dsl::*;
21    /// #
22    /// # // Reading the query result requires reading memory allocated by the
23    /// # // native sqlite library, which miri cannot track provenance for.
24    /// # #[cfg(miri)]
25    /// # fn main() {}
26    /// # #[cfg(not(miri))]
27    /// # fn main() -> QueryResult<()> {
28    /// #     use schema::posts::dsl::*;
29    /// #     let connection = &mut establish_connection();
30    /// let res = posts
31    ///     .select((title, user_id, row_number().partition_by(user_id)))
32    ///     .load::<(String, i32, i64)>(connection)?;
33    /// let expected = vec![
34    ///     ("My first post".to_owned(), 1, 1),
35    ///     ("About Rust".into(), 1, 2),
36    ///     ("My first post too".into(), 2, 1),
37    /// ];
38    /// assert_eq!(expected, res);
39    /// # Ok(())
40    /// # }
41    /// ```
42    #[window]
43    fn row_number() -> BigInt;
44
45    /// Rank of current row within its partition, with gaps
46    ///
47    /// Returns the rank of the current row, with gaps;
48    /// that is, the row_number of the first row in its peer group.
49    ///
50    /// This function must be used as window function. You need to call at least one
51    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
52    /// clause. It cannot be used outside of `SELECT` clauses.
53    ///
54    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
55    ///
56    /// ```
57    /// # include!("../../doctest_setup.rs");
58    /// # use diesel::dsl::*;
59    /// #
60    /// # // Reading the query result requires reading memory allocated by the
61    /// # // native sqlite library, which miri cannot track provenance for.
62    /// # #[cfg(miri)]
63    /// # fn main() {}
64    /// # #[cfg(not(miri))]
65    /// # fn main() -> QueryResult<()> {
66    /// #     use schema::posts::dsl::*;
67    /// #     let connection = &mut establish_connection();
68    /// let res = posts
69    ///     .select((
70    ///         title,
71    ///         user_id,
72    ///         rank().partition_by(user_id).window_order(user_id),
73    ///     ))
74    ///     .load::<(String, i32, i64)>(connection)?;
75    /// let expected = vec![
76    ///     ("My first post".to_owned(), 1, 1),
77    ///     ("About Rust".into(), 1, 1),
78    ///     ("My first post too".into(), 2, 1),
79    /// ];
80    /// assert_eq!(expected, res);
81    /// # Ok(())
82    /// # }
83    /// ```
84    #[window(dialect(
85        BuiltInWindowFunctionRequireOrder,
86        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
87    ))]
88    #[cfg_attr(
89        feature = "mysql_backend",
90        window(backends(diesel::mysql::Mysql), require_order = true)
91    )]
92    #[cfg_attr(
93        feature = "mariadb_backend",
94        window(backends(diesel::mariadb::Mariadb), require_order = true)
95    )]
96    fn rank() -> BigInt;
97
98    /// Rank of current row within its partition, without gaps
99    ///
100    /// Returns the rank of the current row, without gaps;
101    /// this function effectively counts peer groups.
102    ///
103    /// This function must be used as window function. You need to call at least one
104    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
105    /// clause. It cannot be used outside of `SELECT` clauses.
106    ///
107    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
108    ///
109    /// ```
110    /// # include!("../../doctest_setup.rs");
111    /// # use diesel::dsl::*;
112    /// #
113    /// # // Reading the query result requires reading memory allocated by the
114    /// # // native sqlite library, which miri cannot track provenance for.
115    /// # #[cfg(miri)]
116    /// # fn main() {}
117    /// # #[cfg(not(miri))]
118    /// # fn main() -> QueryResult<()> {
119    /// #     use schema::posts::dsl::*;
120    /// #     let connection = &mut establish_connection();
121    /// let res = posts
122    ///     .select((
123    ///         title,
124    ///         user_id,
125    ///         dense_rank().partition_by(user_id).window_order(user_id),
126    ///     ))
127    ///     .load::<(String, i32, i64)>(connection)?;
128    /// let expected = vec![
129    ///     ("My first post".to_owned(), 1, 1),
130    ///     ("About Rust".into(), 1, 1),
131    ///     ("My first post too".into(), 2, 1),
132    /// ];
133    /// assert_eq!(expected, res);
134    /// # Ok(())
135    /// # }
136    /// ```
137    #[window(dialect(
138        BuiltInWindowFunctionRequireOrder,
139        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
140    ))]
141    #[cfg_attr(
142        feature = "mysql_backend",
143        window(backends(diesel::mysql::Mysql), require_order = true)
144    )]
145    #[cfg_attr(
146        feature = "mariadb_backend",
147        window(backends(diesel::mariadb::Mariadb), require_order = true)
148    )]
149    fn dense_rank() -> BigInt;
150
151    /// Percentage rank value
152    ///
153    /// Returns the relative rank of the current row,
154    /// that is (rank - 1) / (total partition rows - 1).
155    /// The value thus ranges from 0 to 1 inclusive.
156    ///
157    /// This function must be used as window function. You need to call at least one
158    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
159    /// clause. It cannot be used outside of `SELECT` clauses.
160    ///
161    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
162    ///
163    /// ```
164    /// # include!("../../doctest_setup.rs");
165    /// # use diesel::dsl::*;
166    /// #
167    /// # // Reading the query result requires reading memory allocated by the
168    /// # // native sqlite library, which miri cannot track provenance for.
169    /// # #[cfg(miri)]
170    /// # fn main() {}
171    /// # #[cfg(not(miri))]
172    /// # fn main() -> QueryResult<()> {
173    /// #     use schema::posts::dsl::*;
174    /// #     let connection = &mut establish_connection();
175    /// let res = posts
176    ///     .select((
177    ///         title,
178    ///         user_id,
179    ///         percent_rank().partition_by(user_id).window_order(user_id),
180    ///     ))
181    ///     .load::<(String, i32, f64)>(connection)?;
182    /// let expected = vec![
183    ///     ("My first post".to_owned(), 1, 0.0),
184    ///     ("About Rust".into(), 1, 0.0),
185    ///     ("My first post too".into(), 2, 0.0),
186    /// ];
187    /// assert_eq!(expected, res);
188    /// # Ok(())
189    /// # }
190    /// ```
191    #[window(dialect(
192        BuiltInWindowFunctionRequireOrder,
193        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
194    ))]
195    #[cfg_attr(
196        feature = "mysql_backend",
197        window(backends(diesel::mysql::Mysql), require_order = true)
198    )]
199    #[cfg_attr(
200        feature = "mariadb_backend",
201        window(backends(diesel::mariadb::Mariadb), require_order = true)
202    )]
203    fn percent_rank() -> Double;
204
205    /// Cumulative distribution value
206    ///
207    /// Returns the cumulative distribution,
208    /// that is (number of partition rows preceding or peers with current row) / (total partition rows).
209    /// The value thus ranges from 1/N to 1.
210    ///
211    /// This function must be used as window function. You need to call at least one
212    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
213    /// clause. It cannot be used outside of `SELECT` clauses.
214    ///
215    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
216    ///
217    /// ```
218    /// # include!("../../doctest_setup.rs");
219    /// # use diesel::dsl::*;
220    /// #
221    /// # // Reading the query result requires reading memory allocated by the
222    /// # // native sqlite library, which miri cannot track provenance for.
223    /// # #[cfg(miri)]
224    /// # fn main() {}
225    /// # #[cfg(not(miri))]
226    /// # fn main() -> QueryResult<()> {
227    /// #     use schema::posts::dsl::*;
228    /// #     let connection = &mut establish_connection();
229    /// let res = posts
230    ///     .select((
231    ///         title,
232    ///         user_id,
233    ///         cume_dist().partition_by(user_id).window_order(user_id),
234    ///     ))
235    ///     .load::<(String, i32, f64)>(connection)?;
236    /// let expected = vec![
237    ///     ("My first post".to_owned(), 1, 1.0),
238    ///     ("About Rust".into(), 1, 1.0),
239    ///     ("My first post too".into(), 2, 1.0),
240    /// ];
241    /// assert_eq!(expected, res);
242    /// # Ok(())
243    /// # }
244    /// ```
245    #[window(dialect(
246        BuiltInWindowFunctionRequireOrder,
247        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
248    ))]
249    #[cfg_attr(
250        feature = "mysql_backend",
251        window(backends(diesel::mysql::Mysql), require_order = true)
252    )]
253    #[cfg_attr(
254        feature = "mariadb_backend",
255        window(backends(diesel::mariadb::Mariadb), require_order = true)
256    )]
257    fn cume_dist() -> Double;
258
259    /// Bucket number of current row within its partition
260    ///
261    /// Returns an integer ranging from 1 to the argument value,
262    /// dividing the partition as equally as possible.
263    ///
264    ///
265    /// This function must be used as window function. You need to call at least one
266    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
267    /// clause. It cannot be used outside of `SELECT` clauses.
268    ///
269    /// ```
270    /// # include!("../../doctest_setup.rs");
271    /// # use diesel::dsl::*;
272    /// #
273    /// # // Reading the query result requires reading memory allocated by the
274    /// # // native sqlite library, which miri cannot track provenance for.
275    /// # #[cfg(miri)]
276    /// # fn main() {}
277    /// # #[cfg(not(miri))]
278    /// # fn main() -> QueryResult<()> {
279    /// #     use schema::posts::dsl::*;
280    /// #     let connection = &mut establish_connection();
281    /// let res = posts
282    ///     .select((title, user_id, ntile(2).partition_by(user_id)))
283    ///     .load::<(String, i32, i32)>(connection)?;
284    /// let expected = vec![
285    ///     ("My first post".to_owned(), 1, 1),
286    ///     ("About Rust".into(), 1, 2),
287    ///     ("My first post too".into(), 2, 1),
288    /// ];
289    /// assert_eq!(expected, res);
290    /// # Ok(())
291    /// # }
292    /// ```
293    #[window]
294    fn ntile(num_buckets: Integer) -> Integer;
295
296    /// Value of argument from row lagging current row within partition
297    ///
298    /// Returns value evaluated at the row that is one row before the current
299    /// row within the partition. If there is no such row, NULL is returned instead.
300    ///
301    /// See [`lag_with_offset`] and [`lag_with_offset_and_default`] for variants with configurable offset
302    /// and default values.
303    ///
304    /// This function must be used as window function. You need to call at least one
305    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
306    /// clause. It cannot be used outside of `SELECT` clauses.
307    ///
308    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
309    ///
310    /// ```
311    /// # include!("../../doctest_setup.rs");
312    /// # use diesel::dsl::*;
313    /// #
314    /// # // Reading the query result requires reading memory allocated by the
315    /// # // native sqlite library, which miri cannot track provenance for.
316    /// # #[cfg(miri)]
317    /// # fn main() {}
318    /// # #[cfg(not(miri))]
319    /// # fn main() -> QueryResult<()> {
320    /// #     use schema::posts::dsl::*;
321    /// #     let connection = &mut establish_connection();
322    /// let res = posts
323    ///     .select((
324    ///         title,
325    ///         user_id,
326    ///         lag(id).partition_by(user_id).window_order(user_id),
327    ///     ))
328    ///     .load::<(String, i32, Option<i32>)>(connection)?;
329    /// let expected = vec![
330    ///     ("My first post".to_owned(), 1, None),
331    ///     ("About Rust".into(), 1, Some(1)),
332    ///     ("My first post too".into(), 2, None),
333    /// ];
334    /// assert_eq!(expected, res);
335    /// # Ok(())
336    /// # }
337    /// ```
338    #[window(dialect(
339        BuiltInWindowFunctionRequireOrder,
340        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
341    ))]
342    #[cfg_attr(
343        feature = "mysql_backend",
344        window(backends(diesel::mysql::Mysql), require_order = true)
345    )]
346    #[cfg_attr(
347        feature = "mariadb_backend",
348        window(backends(diesel::mariadb::Mariadb), require_order = true)
349    )]
350    fn lag<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>>(value: T)
351    -> T::Nullable;
352
353    /// Value of argument from row lagging current row within partition
354    ///
355    /// Returns value evaluated at the row that is offset rows before the current
356    /// row within the partition; If there is no such row, NULL is returned instead.
357    ///
358    /// This function must be used as window function. You need to call at least one
359    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
360    /// clause. It cannot be used outside of `SELECT` clauses.
361    ///
362    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
363    ///
364    /// ```
365    /// # include!("../../doctest_setup.rs");
366    /// # use diesel::dsl::*;
367    /// #
368    /// # // Reading the query result requires reading memory allocated by the
369    /// # // native sqlite library, which miri cannot track provenance for.
370    /// # #[cfg(miri)]
371    /// # fn main() {}
372    /// # #[cfg(not(miri))]
373    /// # fn main() -> QueryResult<()> {
374    /// #     use schema::posts::dsl::*;
375    /// #     let connection = &mut establish_connection();
376    /// let res = posts
377    ///     .select((
378    ///         title,
379    ///         user_id,
380    ///         lag_with_offset(id, 1)
381    ///             .partition_by(user_id)
382    ///             .window_order(user_id),
383    ///     ))
384    ///     .load::<(String, i32, Option<i32>)>(connection)?;
385    /// let expected = vec![
386    ///     ("My first post".to_owned(), 1, None),
387    ///     ("About Rust".into(), 1, Some(1)),
388    ///     ("My first post too".into(), 2, None),
389    /// ];
390    /// assert_eq!(expected, res);
391    /// # Ok(())
392    /// # }
393    /// ```
394    #[doc(alias = "lag")]
395    #[sql_name = "lag"]
396    #[window(dialect(
397        BuiltInWindowFunctionRequireOrder,
398        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
399    ))]
400    #[cfg_attr(
401        feature = "mysql_backend",
402        window(backends(diesel::mysql::Mysql), require_order = true)
403    )]
404    #[cfg_attr(
405        feature = "mariadb_backend",
406        window(backends(diesel::mariadb::Mariadb), require_order = true)
407    )]
408    fn lag_with_offset<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>>(
409        value: T,
410        offset: Integer,
411    ) -> T::Nullable;
412
413    /// Value of argument from row lagging current row within partition
414    ///
415    /// Returns value evaluated at the row that is offset rows before the current
416    /// row within the partition; if there is no such row, instead returns default
417    /// (which must be of a type compatible with value).
418    /// Both offset and default are evaluated with respect to the current row.
419    /// If omitted, offset defaults to 1 and default to NULL.
420    ///
421    /// This function returns a nullable value if either the value or the default expression are
422    /// nullable.
423    ///
424    /// This function must be used as window function. You need to call at least one
425    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
426    /// clause. It cannot be used outside of `SELECT` clauses.
427    ///
428    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
429    ///
430    /// ```
431    /// # include!("../../doctest_setup.rs");
432    /// # use diesel::dsl::*;
433    /// #
434    /// # // Reading the query result requires reading memory allocated by the
435    /// # // native sqlite library, which miri cannot track provenance for.
436    /// # #[cfg(not(feature = "mariadb"))]
437    /// # #[cfg(miri)]
438    /// # fn main() {}
439    /// # #[cfg(all(not(miri), not(feature = "mariadb")))]
440    /// # fn main() -> QueryResult<()> {
441    /// #     use schema::posts::dsl::*;
442    /// #     use diesel::sql_types::{Integer, Nullable};
443    /// #     let connection = &mut establish_connection();
444    /// let res = posts
445    ///     .select((
446    ///         title,
447    ///         user_id,
448    ///         lag_with_offset_and_default(id, 1, user_id)
449    ///             .partition_by(user_id)
450    ///             .window_order(user_id),
451    ///     ))
452    ///     .load::<(String, i32, i32)>(connection)?;
453    /// let expected = vec![
454    ///     ("My first post".to_owned(), 1, 1),
455    ///     ("About Rust".into(), 1, 1),
456    ///     ("My first post too".into(), 2, 2),
457    /// ];
458    /// assert_eq!(expected, res);
459    ///
460    /// let res = posts
461    ///     .select((
462    ///         title,
463    ///         user_id,
464    ///         lag_with_offset_and_default(None::<i32>.into_sql::<Nullable<Integer>>(), 1, user_id)
465    ///             .partition_by(user_id)
466    ///             .window_order(user_id),
467    ///     ))
468    ///     .load::<(String, i32, Option<i32>)>(connection)?;
469    /// let expected = vec![
470    ///     ("My first post".to_owned(), 1, Some(1)),
471    ///     ("About Rust".into(), 1, None),
472    ///     ("My first post too".into(), 2, Some(2)),
473    /// ];
474    /// assert_eq!(expected, res);
475    ///
476    /// let res = posts
477    ///     .select((
478    ///         title,
479    ///         user_id,
480    ///         lag_with_offset_and_default(id, 1, None::<i32>.into_sql::<Nullable<Integer>>())
481    ///             .partition_by(user_id)
482    ///             .window_order(user_id),
483    ///     ))
484    ///     .load::<(String, i32, Option<i32>)>(connection)?;
485    /// let expected = vec![
486    ///     ("My first post".to_owned(), 1, None),
487    ///     ("About Rust".into(), 1, Some(1)),
488    ///     ("My first post too".into(), 2, None),
489    /// ];
490    /// assert_eq!(expected, res);
491    /// # Ok(())
492    /// # }
493    /// # #[cfg(feature = "mariadb")]
494    /// # fn main() {}
495    /// ```
496    #[doc(alias = "lag")]
497    #[sql_name = "lag"]
498    #[window(dialect(
499        BuiltInWindowFunctionRequireOrder,
500        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
501    ))]
502    #[cfg_attr(
503        feature = "mysql_backend",
504        window(backends(diesel::mysql::Mysql), require_order = true)
505    )]
506    #[cfg_attr(
507        feature = "mariadb_backend",
508        window(backends(diesel::mariadb::Mariadb), require_order = true)
509    )]
510    fn lag_with_offset_and_default<
511        T: SqlType
512            + SingleValue
513            + IntoNotNullable<NotNullable: self::private::SameType<T2::NotNullable>>
514            + CombinedNullableValue<T2, T::NotNullable>,
515        T2: SqlType + SingleValue + IntoNotNullable,
516    >(
517        value: T,
518        offset: Integer,
519        default: T2,
520    ) -> T::Out;
521
522    /// Value of argument from row leading current row within partition
523    ///
524    /// Returns value evaluated at the row that is offset rows after the current
525    /// row within the partition; if there is no such row,
526    /// `NULL` will be returned instead.
527    ///
528    /// See [`lead_with_offset`] and [`lead_with_offset_and_default`] for variants with configurable offset
529    /// and default values.
530    ///
531    /// This function must be used as window function. You need to call at least one
532    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
533    /// clause. It cannot be used outside of `SELECT` clauses.
534    ///
535    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
536    ///
537    /// ```
538    /// # include!("../../doctest_setup.rs");
539    /// # use diesel::dsl::*;
540    /// #
541    /// # // Reading the query result requires reading memory allocated by the
542    /// # // native sqlite library, which miri cannot track provenance for.
543    /// # #[cfg(miri)]
544    /// # fn main() {}
545    /// # #[cfg(not(miri))]
546    /// # fn main() -> QueryResult<()> {
547    /// #     use schema::posts::dsl::*;
548    /// #     let connection = &mut establish_connection();
549    /// let res = posts
550    ///     .select((
551    ///         title,
552    ///         user_id,
553    ///         lead(id).partition_by(user_id).window_order(user_id),
554    ///     ))
555    ///     .load::<(String, i32, Option<i32>)>(connection)?;
556    /// let expected = vec![
557    ///     ("My first post".to_owned(), 1, Some(2)),
558    ///     ("About Rust".into(), 1, None),
559    ///     ("My first post too".into(), 2, None),
560    /// ];
561    /// assert_eq!(expected, res);
562    /// # Ok(())
563    /// # }
564    /// ```
565    #[window(dialect(
566        BuiltInWindowFunctionRequireOrder,
567        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
568    ))]
569    #[cfg_attr(
570        feature = "mysql_backend",
571        window(backends(diesel::mysql::Mysql), require_order = true)
572    )]
573    #[cfg_attr(
574        feature = "mariadb_backend",
575        window(backends(diesel::mariadb::Mariadb), require_order = true)
576    )]
577    fn lead<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>>(
578        value: T,
579    ) -> T::Nullable;
580
581    /// Value of argument from row leading current row within partition
582    ///
583    /// Returns value evaluated at the row that is offset rows after the current
584    /// row within the partition; if there is no such row,
585    /// `NULL` is returned instead
586    ///
587    ///
588    /// This function must be used as window function. You need to call at least one
589    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
590    /// clause. It cannot be used outside of `SELECT` clauses.
591    ///
592    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
593    ///
594    /// ```
595    /// # include!("../../doctest_setup.rs");
596    /// # use diesel::dsl::*;
597    /// #
598    /// # // Reading the query result requires reading memory allocated by the
599    /// # // native sqlite library, which miri cannot track provenance for.
600    /// # #[cfg(miri)]
601    /// # fn main() {}
602    /// # #[cfg(not(miri))]
603    /// # fn main() -> QueryResult<()> {
604    /// #     use schema::posts::dsl::*;
605    /// #     let connection = &mut establish_connection();
606    /// let res = posts
607    ///     .select((
608    ///         title,
609    ///         user_id,
610    ///         lead_with_offset(id, 1)
611    ///             .partition_by(user_id)
612    ///             .window_order(user_id),
613    ///     ))
614    ///     .load::<(String, i32, Option<i32>)>(connection)?;
615    /// let expected = vec![
616    ///     ("My first post".to_owned(), 1, Some(2)),
617    ///     ("About Rust".into(), 1, None),
618    ///     ("My first post too".into(), 2, None),
619    /// ];
620    /// assert_eq!(expected, res);
621    /// # Ok(())
622    /// # }
623    /// ```
624    #[doc(alias = "lead")]
625    #[sql_name = "lead"]
626    #[window(dialect(
627        BuiltInWindowFunctionRequireOrder,
628        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
629    ))]
630    #[cfg_attr(
631        feature = "mysql_backend",
632        window(backends(diesel::mysql::Mysql), require_order = true)
633    )]
634    #[cfg_attr(
635        feature = "mariadb_backend",
636        window(backends(diesel::mariadb::Mariadb), require_order = true)
637    )]
638    fn lead_with_offset<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>>(
639        value: T,
640        offset: Integer,
641    ) -> T::Nullable;
642
643    /// Value of argument from row leading current row within partition
644    ///
645    /// Returns value evaluated at the row that is offset rows after the current
646    /// row within the partition; if there is no such row,
647    /// instead returns default (which must be of a type compatible with value).
648    /// Both offset and default are evaluated with respect to the current row.
649    /// If omitted, offset defaults to 1 and default to NULL.
650    ///
651    /// This function returns a nullable value if either the value or the default expression are
652    /// nullable.
653    ///
654    /// This function must be used as window function. You need to call at least one
655    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
656    /// clause. It cannot be used outside of `SELECT` clauses.
657    ///
658    /// For MySQL this function requires you to call [`.window_order()`](WindowExpressionMethods::window_order())
659    ///
660    /// ```
661    /// # include!("../../doctest_setup.rs");
662    /// # use diesel::dsl::*;
663    /// #
664    /// # // Reading the query result requires reading memory allocated by the
665    /// # // native sqlite library, which miri cannot track provenance for.
666    /// # #[cfg(not(feature = "mariadb"))]
667    /// # #[cfg(miri)]
668    /// # fn main() {}
669    /// # #[cfg(all(not(miri), not(feature = "mariadb")))]
670    /// # fn main() -> QueryResult<()> {
671    /// #     use schema::posts::dsl::*;
672    /// #     use diesel::sql_types::{Integer, Nullable};
673    /// #     let connection = &mut establish_connection();
674    /// let res = posts
675    ///     .select((
676    ///         title,
677    ///         user_id,
678    ///         lead_with_offset_and_default(id, 1, user_id)
679    ///             .partition_by(user_id)
680    ///             .window_order(user_id),
681    ///     ))
682    ///     .load::<(String, i32, i32)>(connection)?;
683    /// let expected = vec![
684    ///     ("My first post".to_owned(), 1, 2),
685    ///     ("About Rust".into(), 1, 1),
686    ///     ("My first post too".into(), 2, 2),
687    /// ];
688    /// assert_eq!(expected, res);
689    ///
690    /// let res = posts
691    ///     .select((
692    ///         title,
693    ///         user_id,
694    ///         lead_with_offset_and_default(None::<i32>.into_sql::<Nullable<Integer>>(), 1, user_id)
695    ///             .partition_by(user_id)
696    ///             .window_order(user_id),
697    ///     ))
698    ///     .load::<(String, i32, Option<i32>)>(connection)?;
699    /// let expected = vec![
700    ///     ("My first post".to_owned(), 1, None),
701    ///     ("About Rust".into(), 1, Some(1)),
702    ///     ("My first post too".into(), 2, Some(2)),
703    /// ];
704    /// assert_eq!(expected, res);
705    ///
706    /// let res = posts
707    ///     .select((
708    ///         title,
709    ///         user_id,
710    ///         lead_with_offset_and_default(id, 1, None::<i32>.into_sql::<Nullable<Integer>>())
711    ///             .partition_by(user_id)
712    ///             .window_order(user_id),
713    ///     ))
714    ///     .load::<(String, i32, Option<i32>)>(connection)?;
715    /// let expected = vec![
716    ///     ("My first post".to_owned(), 1, Some(2)),
717    ///     ("About Rust".into(), 1, None),
718    ///     ("My first post too".into(), 2, None),
719    /// ];
720    /// assert_eq!(expected, res);
721    /// # Ok(())
722    /// # }
723    /// # #[cfg(feature = "mariadb")]
724    /// # fn main() {}
725    /// ```
726    #[doc(alias = "lead")]
727    #[sql_name = "lead"]
728    #[window(dialect(
729        BuiltInWindowFunctionRequireOrder,
730        crate::backend::sql_dialect::built_in_window_function_require_order::NoOrderRequired
731    ))]
732    #[cfg_attr(
733        feature = "mysql_backend",
734        window(backends(diesel::mysql::Mysql), require_order = true)
735    )]
736    #[cfg_attr(
737        feature = "mariadb_backend",
738        window(backends(diesel::mariadb::Mariadb), require_order = true)
739    )]
740    fn lead_with_offset_and_default<
741        T: SqlType
742            + SingleValue
743            + IntoNotNullable<NotNullable: self::private::SameType<T2::NotNullable>>
744            + CombinedNullableValue<T2, T::NotNullable>,
745        T2: SqlType + SingleValue + IntoNotNullable,
746    >(
747        value: T,
748        offset: Integer,
749        default: T2,
750    ) -> T::Out;
751
752    /// Value of argument from first row of window frame
753    ///
754    /// Returns value evaluated at the row that is the first row of the window frame.
755    ///
756    ///
757    /// This function must be used as window function. You need to call at least one
758    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
759    /// clause. It cannot be used outside of `SELECT` clauses.
760    ///
761    /// ```
762    /// # include!("../../doctest_setup.rs");
763    /// # use diesel::dsl::*;
764    /// #
765    /// # // Reading the query result requires reading memory allocated by the
766    /// # // native sqlite library, which miri cannot track provenance for.
767    /// # #[cfg(miri)]
768    /// # fn main() {}
769    /// # #[cfg(not(miri))]
770    /// # fn main() -> QueryResult<()> {
771    /// #     use schema::posts::dsl::*;
772    /// #     let connection = &mut establish_connection();
773    /// let res = posts
774    ///     .select((title, user_id, first_value(id).partition_by(user_id)))
775    ///     .load::<(String, i32, i32)>(connection)?;
776    /// let expected = vec![
777    ///     ("My first post".to_owned(), 1, 1),
778    ///     ("About Rust".into(), 1, 1),
779    ///     ("My first post too".into(), 2, 3),
780    /// ];
781    /// assert_eq!(expected, res);
782    /// # Ok(())
783    /// # }
784    /// ```
785    #[window]
786    fn first_value<T: SqlType + SingleValue>(value: T) -> T;
787
788    /// Value of argument from last row of window frame
789    ///
790    /// Returns value evaluated at the row that is the last row of the window frame.
791    ///
792    ///
793    /// This function must be used as window function. You need to call at least one
794    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
795    /// clause. It cannot be used outside of `SELECT` clauses.
796    ///
797    /// ```
798    /// # include!("../../doctest_setup.rs");
799    /// # use diesel::dsl::*;
800    /// #
801    /// # // Reading the query result requires reading memory allocated by the
802    /// # // native sqlite library, which miri cannot track provenance for.
803    /// # #[cfg(miri)]
804    /// # fn main() {}
805    /// # #[cfg(not(miri))]
806    /// # fn main() -> QueryResult<()> {
807    /// #     use schema::posts::dsl::*;
808    /// #     let connection = &mut establish_connection();
809    /// let res = posts
810    ///     .select((title, user_id, last_value(id).partition_by(user_id)))
811    ///     .load::<(String, i32, i32)>(connection)?;
812    /// let expected = vec![
813    ///     ("My first post".to_owned(), 1, 2),
814    ///     ("About Rust".into(), 1, 2),
815    ///     ("My first post too".into(), 2, 3),
816    /// ];
817    /// assert_eq!(expected, res);
818    /// # Ok(())
819    /// # }
820    /// ```
821    #[window]
822    fn last_value<T: SqlType + SingleValue>(value: T) -> T;
823
824    /// Value of argument from N-th row of window frame
825    ///
826    /// Returns value evaluated at the row that is the n'th row of the window frame (counting from 1);
827    /// returns NULL if there is no such row.
828    ///
829    ///
830    /// This function must be used as window function. You need to call at least one
831    /// of the methods [`WindowExpressionMethods`] from to use this function in your `SELECT`
832    /// clause. It cannot be used outside of `SELECT` clauses.
833    ///
834    /// ```
835    /// # include!("../../doctest_setup.rs");
836    /// # use diesel::dsl::*;
837    /// #
838    /// # // Reading the query result requires reading memory allocated by the
839    /// # // native sqlite library, which miri cannot track provenance for.
840    /// # #[cfg(miri)]
841    /// # fn main() {}
842    /// # #[cfg(not(miri))]
843    /// # fn main() -> QueryResult<()> {
844    /// #     use schema::posts::dsl::*;
845    /// #     let connection = &mut establish_connection();
846    /// let res = posts
847    ///     .select((title, user_id, nth_value(id, 2).partition_by(user_id)))
848    ///     .load::<(String, i32, Option<i32>)>(connection)?;
849    /// let expected = vec![
850    ///     ("My first post".to_owned(), 1, Some(2)),
851    ///     ("About Rust".into(), 1, Some(2)),
852    ///     ("My first post too".into(), 2, None),
853    /// ];
854    /// assert_eq!(expected, res);
855    /// # Ok(())
856    /// # }
857    /// ```
858    #[window]
859    fn nth_value<T: SqlType + SingleValue + IntoNullable<Nullable: SingleValue>>(
860        value: T,
861        n: Integer,
862    ) -> T::Nullable;
863}
864
865mod private {
866    pub trait SameType<T> {}
867
868    impl<T> SameType<T> for T {}
869}