Skip to content

How to run custom functions / expressions? #322

Answered by ikrivosheev
jabdr asked this question in Q&A
Discussion options

You must be logged in to vote

@jabdr hello! Sorry for delay...

use sea_query::*;

#[derive(Iden)]
enum People {
    Table,
    City,
    Name,
}

fn main() {
    let query = Query::select()
        .column(People::City)
        .expr_as(
            Expr::cust("GROUP_CONCAT(DISTINCT `name` ORDER BY `name` SEPARATOR ';')"),
            Alias::new("names"),
        )
        .from(People::Table)
        .and_where(Expr::cust("`city` REGEXP '^[a-f].*'"))
        .group_by_col(People::City)
        .order_by(People::City, Order::Asc)
        .to_owned();
    println!("{}", query.to_string(MysqlQueryBuilder));
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by billy1624
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants