Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parentheses for complex LIKE query is different than the same Postgres ILIKE query #776

Open
jcrossley3 opened this issue May 2, 2024 · 1 comment

Comments

@jcrossley3
Copy link

Description

When I changed from LIKE to ILIKE I noticed I was getting a lot more parentheses in my queries. I would expect the precedence rules for both to be the same, therefore I'd expect the resulting parentheses to be the same.

Steps to Reproduce

  1. Modify the select_22 test to use ilike instead of like, like so:
#[test]
fn select_22() {
    use sea_query::extension::postgres::PgExpr;
    assert_eq!(
        Query::select()
            .column(Char::Character)
            .from(Char::Table)
            .cond_where(
                Cond::all()
                    .add(
                        Cond::any().add(Expr::col(Char::Character).ilike("C")).add(
                            Expr::col(Char::Character)
                                .ilike("D")
                                .and(Expr::col(Char::Character).ilike("E"))
                        )
                    )
                    .add(
                        Expr::col(Char::Character)
                            .ilike("F")
                            .or(Expr::col(Char::Character).ilike("G"))
                    )
            )
            .to_string(PostgresQueryBuilder),
        r#"SELECT "character" FROM "character" WHERE ("character" ILIKE 'C' OR ("character" ILIKE 'D' AND "character" ILIKE 'E')) AND ("character" ILIKE 'F' OR "character" ILIKE 'G')"#
    );
}

Expected Behavior

SELECT "character" FROM "character" WHERE ("character" ILIKE 'C' OR ("character" ILIKE 'D' AND "character" ILIKE 'E')) AND ("character" ILIKE 'F' OR "character" ILIKE 'G')

Actual Behavior

SELECT "character" FROM "character" WHERE (("character" ILIKE 'C') OR (("character" ILIKE 'D') AND ("character" ILIKE 'E'))) AND (("character" ILIKE 'F') OR ("character" ILIKE 'G'))

Reproduces How Often

Yep

Versions

The postgres extension of v0.31.0-rc.5

@tyt2y3
Copy link
Member

tyt2y3 commented May 4, 2024

may be it will be a good idea to make ILIKE a built-in operator. now it is not, as it is Postgres specific

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants