Allow any()/all() on LHS to allow ANY(set) ~ pattern#264
Allow any()/all() on LHS to allow ANY(set) ~ pattern#264mlell wants to merge 2 commits intobeancount:masterfrom
Conversation
Allow functions/operators registered with unparameterized types (e.g., set) to match operands with parameterized generic types (e.g., typing.Set[str]).
There were two matching operators: * subject ~ pattern (case-insensitive) * pattern ?~ subject (case-sensitive) This is somewhat confusing, but allows for this: SELECT * WHERE "Assets:" ?~ ANY(accounts) The ANY operator was only allowed on the RHS. This commit extends it, so it can be used on either side, allowing for SELECT WHERE ANY(accounts) ~ "Assets:"
|
Thanks for the contribution. However, AFAIK in SQL |
|
Hello, thanks for taking a look on it! No, I am not aware of any SQL dialect which allows this. However, I was not able to find the reasons for it. People instead use subqueries, so they write, e.g. in PostgreSQL SELECT * FROM book where EXISTS ( SELECT * from unnest(author) as X where x ~* '^p' ) instead of the more intutitive (but non-syntactical) SELECT ANY(authors) ~* '^p' FROM book;I for myself are not yet super experienced with SQL, and we certainly agree that beanquery should not be limited to SQL engineers who would notice such a thing. Moreover, BQL does deviate from SQL at times, with the motivation to make it easier to write queries. For example with the semantics of I have the intuition that I have not found any reason for this design decision in SQLs. For me, this change reduces the mental load of writing BQL queries and makes it more pleasant to use, so I thought I would turn the newbies' frustration into something productive and propose this change |
There were two matching operators:
This is somewhat confusing for newcomers. The reason maybe is that it allows for this:
which is used for example by the function
has_accountby AST transformation. The ANY operator so far was only allowed on the RHS, therefore~could not be used for the above example. This commit extends it, so it can be used on either side, allowing forTests pass, also subqueries within any() are still possible!
Moreover, this Pull request solves the issue that some columns are
@registered for the typetyping.Set[str]but some functions/operators are registered forset, which did not match. They do now, making functions more flexibly applicable