Multiple Filters
kanekoshoyu opened this issue · comments
Hi,
I was wondering if there is any plan or a current workaround for using multiple filters (esp on select and update)
Originally I had a misunderstanding on AST builder syntax and I thought adding .filter() multiple times will keep adding nested filter, but turns out every new filter was just overriding another filter.
Then I tried adding AND within one filter expression, but I do not see the effect of the nested filter. From what I tested, it seems like only the first condition in the filter gets recognized, and the rest is discarded.
I saw online that we might be able to use subqueries (queries on top of queries) to get it solved. I am wondering if there is anything similar to such a concept in gluesql that I can use as a workaround.
Example of AND/OR within WHERE
https://www.techonthenet.com/sql/where.php
To use AND or OR expression, you should do like this.
.filter(
col("name")
.not_like(text("D%"))
.and(col("name").not_like(text("M___"))),
)
https://github.com/gluesql/gluesql/blob/main/test-suite/src/ast_builder/expr/pattern_matching.rs#L69
or
.filter("c.name = 'Fruit' OR c.name = 'Meat'")
https://github.com/gluesql/gluesql/blob/main/test-suite/src/ast_builder/select.rs#L85
Originally I had a misunderstanding on AST builder syntax and I thought adding .filter() multiple times will keep adding nested filter, but turns out every new filter was just overriding another filter.
adding filter multiple times should work like below,
if it wasn't then could you provide the query you tested?
gluesql/core/src/ast_builder/select/filter.rs
Lines 142 to 150 in 235fd6e
To use AND or OR expression, you should do like this.
.filter( col("name") .not_like(text("D%")) .and(col("name").not_like(text("M___"))), )https://github.com/gluesql/gluesql/blob/main/test-suite/src/ast_builder/expr/pattern_matching.rs#L69 or
.filter("c.name = 'Fruit' OR c.name = 'Meat'")https://github.com/gluesql/gluesql/blob/main/test-suite/src/ast_builder/select.rs#L85
Sure, this worked fine for select(). for update() I tried the other day and was not working.
Sure, this worked fine for select(). for update() I tried the other day and was not working.
thanks, yes it was only working for select().
I've just added concat filter support to ast builder update nodes.
this will be included in the next release.
ref.
Update AST builder UpdateFilterNode .filter(..) behavior, #1455
Update AST builder UpdateNode to enforce .filter(..) before .set(..), #1454