SQLite Forum

operator precedence docs missing, suggested clarifications below
(Reformatted quote for clarity. Answered separately because I forgot it earlier.)

> This is important to the extent that the docs do not tell you if<code>
  select not 0 between -1 and 2;
</code>means this:<code>
  select (not 0) between -1 and 2;  -- it does not
</code>or this:<code>
  select not (0 between -1 and 2);  -- it does

But the docs do tell you which alternative is chosen. NOT clearly has higher precedence than BETWEEN, (per Section 6 and Section 2 para 2), so it is inarguable that your first alternative is correct. And I have to wonder how you conclude the contrary.

(Edited to add:)

Now that I revisit your proofs, and run your (well contrived) examples, I think there is a discrepancy between the documented grammar and the implemented grammar. My reading of the docs sections 2 and 6 leaves no possibility that the leading "not" will fail to group with the "0", leaving that "0" to become part of the between-and expression.  This will definitely get a closer look, and either I will become a better reader or the said doc sections will be corrected. (I do not count an implementation change among the possibilities.)

(Edited further to add:)

A close reread of the doc on precedence shows nothing to support "NOT clearly has higher precedence than BETWEEN". The doc says nothing of NOT's precedence, but soon will. In my not-quite-supported thinking, because NOT is on the same line as unary '+' and '-',<sup><b>a</b></sup> I gave NOT their same precedence. But the precedence by row rank statement only applies to the preceding paragraph's binary operators.


<b>a.</b> This mistake was undoubtedly aided by the fact that in C/C++ (and I don't know how many other languages), logical not (aka '!') and unary '+' and '-' have high and identical precedence. The late hour may have been a factor too.