SQLite Forum

operator precedence docs missing, suggested clarifications below
Login
To be clear, what is written is correct.  I found no flaws.  But as a person trying to understand the relative order of the operators I found that the fact that there was no one total ordering specified to leave me with questions.  So I conducted a few experiments to lock down the order.

From these I concluded the extra facts about where NOT, ~, -, and BETWEEN go.

This is important to the extent that the docs do not tell you if

select not 0 between -1 and 2;

means this:

```
select (not 0) between -1 and 2;  -- it does not
```
or this:

```
select not (0 between -1 and 2);  -- it does
```

The proofs are just statements engineered so that the answer would be different depending on the ordering.  Then you compare the one with the forced parens to the no parens and you can easily see what the ordering is.

The grammer:

```
%left OR.
%left AND.
%right NOT.
%left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
%left GT LE LT GE.
%right ESCAPE.
%left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left STAR SLASH REM.
%left CONCAT.
%left COLLATE.
%right BITNOT.
```

Seems to be right in line with what I discovered by experimentation.

I think the full list would make a nice addition to the docs.