-
Notifications
You must be signed in to change notification settings - Fork 58
Mathematical operations in where #20
Comments
It looks like the grammar isn't happy with the parenthesis on the left side ( Looking at it closer, there appears to also be a problem when trying to switch the two sides of the inner expression: SELECT * FROM temptable where value1 = (value3 * -1 + (value2 * 5)) Currently, the parser is treating this as if it is the expression: |
Based on further investigation, the expression parsing works for simple expressions, but is not obeying order of operations or correctly composing complex expressions. For example: -- parsed as -(1 * (2+3)) instead of (-1) * (2 + 3)
SELECT * FROM t where -1 * (2 + 3)
-- parsed as 3 + (4 * (5 > 20)) instead of (3 + (4 * 5)) > 20
SELECT * FROM t where 3 + 4 * 5 > 20 I will need to rewrite the expression parsing grammar for the next release to:
Expect these changes in release |
Better support for order of operations and correct order when composing expressions using AND, OR, etc... Also fixed issue where expressions such as `x NOT NULL` were treated as a unary expressions instead of binary expressions. WIP - Do not merge
Got rid of a bunch of unused code, cleaned up the utility functions, moved the utilities back into the grammar.pegjs file to avoid the extra magic of injecting the import statement into the built parser. Fixed the binary expression logic to properly handle cases such as: ``` sql SELECT * FROM t where -1 * (2 + 3); SELECT * FROM t where 3 + 4 * 5 > 20; SELECT * FROM t where v1 = ((v2 * 5) - v3); ``` Updated SQL in specs to contain correct ASTs for specs related to expression grouping. Should have broken this into several commits but the changes are too intertwined to easily break apart now. Refs #20 Refs #3
@anvog I just released a beta version of the parser that contains the fix for the issue you were experiencing 0.15.0-beta. You can install it via npm using (for now):
or, you can also try it out online here. Let me know if you encounter any more problems, thanks! |
Whoops, didn't mean to close this one just yet. Will close after 0.15.0 is out of beta. |
The format expr BETWEEN expr AND expr was failing to be parsed after the latest round of changes.
Closing this one, but still need
|
SELECT * FROM temptable where value1 = ((value2 * 5) - value3)
The statement above will throw the error.
Brackets should be fine.
Any other way to structure the equations?
The text was updated successfully, but these errors were encountered: