pony icon indicating copy to clipboard operation
pony copied to clipboard

select(p for p in P if (v1 < p.field < v2)) does not work

Open socketpair opened this issue 9 years ago • 6 comments

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!

socketpair avatar Oct 27 '14 19:10 socketpair

As I described somewhere, this is known behavior. Currently, there are only two kind of expressions which bytecode cannot be decompiled by Pony:

  1. Conditional expressions: a if b else c
  2. 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 ;)

kozlovsky avatar Oct 27 '14 20:10 kozlovsky

PyCharm recommends to replace pair of conditions to chain condtition. So, if it is not hard, add support of chained conditions...

socketpair avatar Nov 08 '14 04:11 socketpair

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.

TheDataLeek avatar Aug 15 '18 21:08 TheDataLeek

https://docs.ponyorm.com/api_reference.html#between

jgirardet avatar Aug 15 '18 21:08 jgirardet

Ahhh! That's awesome! That's exactly what I need. Thanks!

TheDataLeek avatar Aug 15 '18 21:08 TheDataLeek

OK between is a thing but why not support the chained syntax (6 years later)

Queuecumber avatar Oct 29 '20 17:10 Queuecumber