Comments (2)
I have confirmed this bug as well. Here is another more complex example with several operators, LIKE is the only one that sometimes puts a 'binary' 'and' between the 'left' and 'right'. It seems to be dependent on where the LIKE is in the order of statements too, if the LIKE expression is last it works fine. If you view the AST in a JSON viewer it is very easy to see the issue.
SELECT a, b
FROM x, y
WHERE d = 'X'
AND e BETWEEN '1/1/2018' AND '1/31/2018'
AND f != 'NEW'
AND g >= 1000000
AND (h IS NULL
OR j IS NOT NULL)
AND k LIKE 'Jones%'
AND l IN ('CA', 'OR', 'NY')
{"type":"statement","variant":"list","statement":[{"type":"statement","variant":"select","result":[{"type":"identifier","variant":"column","name":"a"},{"type":"identifier","variant":"column","name":"b"}],"from":{"type":"map","variant":"join","source":{"type":"identifier","variant":"table","name":"x"},"map":[{"type":"join","variant":"cross join","source":{"type":"identifier","variant":"table","name":"y"}}]},"where":[{"type":"expression","format":"binary","variant":"operation","operation":"and","left":{"type":"expression","format":"binary","variant":"operation","operation":"and","left":{"type":"expression","format":"binary","variant":"operation","operation":"and","left":{"type":"expression","format":"binary","variant":"operation","operation":"and","left":{"type":"expression","format":"binary","variant":"operation","operation":"and","left":{"type":"expression","format":"binary","variant":"operation","operation":"=","left":{"type":"identifier","variant":"column","name":"d"},"right":{"type":"literal","variant":"text","value":"X"}},"right":{"type":"expression","format":"binary","variant":"operation","operation":"between","right":{"type":"expression","format":"binary","variant":"operation","operation":"and","left":{"type":"literal","variant":"text","value":"1/1/2018"},"right":{"type":"literal","variant":"text","value":"1/31/2018"}},"left":{"type":"identifier","variant":"column","name":"e"}}},"right":{"type":"expression","format":"binary","variant":"operation","operation":"!=","left":{"type":"identifier","variant":"column","name":"f"},"right":{"type":"literal","variant":"text","value":"NEW"}}},"right":{"type":"expression","format":"binary","variant":"operation","operation":">=","left":{"type":"identifier","variant":"column","name":"g"},"right":{"type":"literal","variant":"decimal","value":"1000000"}}},"right":{"type":"expression","format":"binary","variant":"operation","operation":"or","left":{"type":"expression","format":"binary","variant":"operation","operation":"is","left":{"type":"identifier","variant":"column","name":"h"},"right":{"type":"literal","variant":"null","value":"null"}},"right":{"type":"expression","format":"binary","variant":"operation","operation":"is not","left":{"type":"identifier","variant":"column","name":"j"},"right":{"type":"literal","variant":"null","value":"null"}}}},"right":{"type":"expression","format":"binary","variant":"operation","operation":"like","right":{"type":"expression","format":"binary","variant":"operation","operation":"and","left":{"type":"literal","variant":"text","value":"Jones%"},"right":{"type":"expression","format":"binary","variant":"operation","operation":"in","right":{"type":"expression","variant":"list","expression":[{"type":"literal","variant":"text","value":"CA"},{"type":"literal","variant":"text","value":"OR"},{"type":"literal","variant":"text","value":"NY"}]},"left":{"type":"identifier","variant":"column","name":"l"}}},"left":{"type":"identifier","variant":"column","name":"k"}}}]}]}
from sqlite-parser.
Here is another minimal example (just two like
expressions joined with an and
), first with parens (correct), second (wrong one) without parens:
> const { statement: [{ where: [where7] }] } = parser("select 1 where (description like 'foo') and (description like 'bar')");
undefined
> where7
{ type: 'expression',
format: 'binary',
variant: 'operation',
operation: 'and',
left:
{ type: 'expression',
format: 'binary',
variant: 'operation',
operation: 'like',
right: { type: 'literal', variant: 'text', value: 'foo' },
left: { type: 'identifier', variant: 'column', name: 'description' } },
right:
{ type: 'expression',
format: 'binary',
variant: 'operation',
operation: 'like',
right: { type: 'literal', variant: 'text', value: 'bar' },
left: { type: 'identifier', variant: 'column', name: 'description' } } }
> const { statement: [{ where: [where9] }] } = parser("select 1 where description like 'foo' and description like 'bar'");
undefined
> where9
{ type: 'expression',
format: 'binary',
variant: 'operation',
operation: 'like',
right:
{ type: 'expression',
format: 'binary',
variant: 'operation',
operation: 'and',
left: { type: 'literal', variant: 'text', value: 'foo' },
right:
{ type: 'expression',
format: 'binary',
variant: 'operation',
operation: 'like',
right: [Object],
left: [Object] } },
left: { type: 'identifier', variant: 'column', name: 'description' } }
from sqlite-parser.
Related Issues (20)
- Node Structure Change: Change format in condition type node to variant HOT 4
- Node Structure Change: Add variant to module node of create virtual table statement. HOT 1
- "too much recursion" in browserified version HOT 7
- Trailing spaces in table or column names deleted
- Get full text of expression HOT 2
- operator precedence of AND/OR in where HOT 3
- use from browser without nodejs HOT 1
- Issue with Object.assign is not a function HOT 3
- Allow for / in the table names HOT 1
- Each expression is evaluated 4 times
- Why are invalid statements parsed without errors? HOT 1
- Support for Interval HOT 2
- Feature Request: add stringify method HOT 1
- Confusion about parsing of "not" operator HOT 1
- BUG: Named constraints lose names if other constraints are present
- split into multiple statements
- Do you have the AST definition document? HOT 1
- OVER clause incorrect validation
- Syntax error when use tokenizer arguments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlite-parser.