SQLite Forum

operator precedence docs missing, suggested clarifications below
Login
First off, this will help a ton. Here are some thoughts that might be useful.

I'll number the points for ease for discussion.

---

## 1 Use of ?

You might use "expr" instead of "?" because of the prevalence of "?" for binding.  No big deal.

## 2 Arrow Notation

The arrow notation for left to right, or right to left  might be misleading.  For instance you use a left arrow to indicate left to right binding but of course a left arrow points from right to left.  I read it backwards at first.  You might be better served by the letters L/R.  That said the notation is clear enough once you're used to the fact that left arrow means left to right.

You can also correctly read it as "the parens go on the left" hence the arrow points left.  The arrow points in the direction of the implicit parens, in which case the arrow is natural.

This is also no big deal.

## 3 The ESCAPE operator

Looking at "% ?" and note 4.  The operator is not "%" but "ESCAPE"

```
sqlite> select 'cx' like 'c%';
1
sqlite> select 'cx' like 'c%' escape 'c';
0
```

The railroad diagram indicates that ESCAPE can be applied to LIKE, GLOB, MATCH and REGEX.  The grammar concurs (LIKE_KW seems to include REGEXP and GLOB though that was tricky to deduce). I had to consult:

```
static const unsigned char aKWCode[147] etc.
```

I've only ever seen ESCAPE used with LIKE.  So I tested this out.

```
sqlite> select 'x' match 'y' escape 'z';
Error: wrong number of arguments to function match()
sqlite> select 'x' glob 'y' escape 'z';
Error: wrong number of arguments to function glob()
sqlite> select 'x' regexp 'y' escape 'z';
Error: no such function: regexp
```
I don't have REGEXP in my build but I bet it's the same as GLOB/MATCH we should try it.

Basically the grammar supports ESCAPE on all 4 but it's only done this way for symmetry.  The conversion from  x match y escape z  to  match(x, y, z) fails because match only supports 2 args.  The others are the same.

So in short we don't need to discuss the fact that the others support [edited typo here] ESCAPE and indeed we might want to fix the railroad diagram too because it's kind of a lie.  It parses but then, psyche, you can't actually do that.

## 4 REGEXP
The operator is REGEXP rather than REGEX

## 5 NOT [BETWEEN|LIKE|IN|MATCH|REGEXP|GLOB] 

You might consider adding "e.g. 'x' NOT LIKE 'y'" to note 5.

##6 My Diagram Had Bugs

My version of the diagram has AND/OR placed incorrectly!  Yours is correct!  I actually posted two versions but one was lost.  They were substantially similar in any case.

---

The fact that we came up with very similar diagrams I think is a good thing.  Your goals/motivations are not identical to mine, yet we ended in a very similar location => seems like a good thing.