pony
pony copied to clipboard
select(p for p in P if (v1 < p.field < v2)) does not work
it raises: NotImplementedError: Expression is too complex to decompile, try to pass query as string, e.g. select("x for x in Something")
First, I thought that Pony will emit BETWEEN
operator. But instead, exception raised.
As I think, Pony should use two (or more) comparison operator instead of BETWEEN
, because:
http://www.w3schools.com/sql/sql_between.asp :
Notice that the BETWEEN operator can produce different result in different databases!
In some databases, BETWEEN selects fields that are between and excluding the test values.
In other databases, BETWEEN selects fields that are between and including the test values.
And in other databases, BETWEEN selects fields between the test values, including the first test value and excluding the last test value.
Therefore: Check how your database treats the BETWEEN operator!
As I described somewhere, this is known behavior. Currently, there are only two kind of expressions which bytecode cannot be decompiled by Pony:
- Conditional expressions:
a if b else c
- Chaining comparisons:
a < b < c
We probably can implement both of it, but it requires spare week, and currently there are more important tasks, like migration support.
While Pony cannot decompile such expressions, it can detect it and raise the exception that you cited. In that case you can pass text of the generator expression as a string, and it will be translated successfully. Also, for chained comparison you can replace a < b < c
to a < b and b < c
, and it will be decompiled successfully from the bytecode.
I don't think that w3schools correct about BETWEEN
. In all databases that I know it has the same meaning a <= b and b <= c
(btw, I've heard already that w3schools is unreliable source of information). But currently Pony doesn't implement BETWEEN
at all, and use expressions like a <= b and b <= c
instead. We can use BETWEEN
for such expressions in the future, but this is just syntactic sugar, so it doesn't placed high on our list of priorities ;)
PyCharm recommends to replace pair of conditions to chain condtition. So, if it is not hard, add support of chained conditions...
It's been a few years since this was discussed, has there been any further progress? It's a feature I'd love to use.
https://docs.ponyorm.com/api_reference.html#between
Ahhh! That's awesome! That's exactly what I need. Thanks!
OK between is a thing but why not support the chained syntax (6 years later)