Skip to content
This repository has been archived by the owner on Jul 15, 2021. It is now read-only.

Confusion about parsing of "not" operator #51

Open
eatonphil opened this issue Jun 14, 2018 · 1 comment
Open

Confusion about parsing of "not" operator #51

eatonphil opened this issue Jun 14, 2018 · 1 comment

Comments

@eatonphil
Copy link

Hi! In the following example I'd expect "not" to be a first-class member of the AST. But it appears to just be concatenated with the operator after it. This would imply I've got to then do string parsing of the operation field if I'm trying to discover "not" use:

> const { statement: [{ where: [where5] }] }  = parser('select 1 where processName =  \'/bin/sh\' and id not like \'foo\'');
undefined
> where5
{ type: 'expression',
  format: 'binary',
  variant: 'operation',
  operation: 'and',
  left:
   { type: 'expression',
     format: 'binary',
     variant: 'operation',
     operation: '=',
     left: { type: 'identifier', variant: 'column', name: 'processname' },
     right: { type: 'literal', variant: 'text', value: '/bin/sh' } },
  right:
   { type: 'expression',
     format: 'binary',
     variant: 'operation',
     operation: 'not like',
     right: { type: 'literal', variant: 'text', value: 'foo' },
     left: { type: 'identifier', variant: 'column', name: 'id' } } }

Is this intentional? I'd expect the AST to look more like:

  ...
  right:
   { type: 'expression',
     format: 'unary',
     variant: 'operation',
     operation: 'not',
     expression:
     {  type: 'expression',
        format: 'binary',
        variant: 'operation',
        operation: 'like',
        right: { type: 'literal', variant: 'text', value: 'foo' },
        left: { type: 'identifier', variant: 'column', name: 'id' } } } }
@emilioplatzer
Copy link

emilioplatzer commented Jan 29, 2021

I think that is not in this case. In a not like b that means: not (a like b), but not a not (like b) because not is an unary operator. Then they can parse as a "notlike" b.

There still a problem with not

Here I have an example:

select (not 1) + 1, not (1 + 1), not 1 + 1

If you write it in sqllite http://sqlfiddle.com/#!7/9eecb7/7512 you can see that not 1 + 1 means not (1 + 1) but not (not 1) + 1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants