Operator Precedence

You are viewing an old version of this article. View the current version here.

The precedence is the order in which the SQL operators are evaluated.

The following list shows the SQL operator precedence. Operators that appear first in the list have a higher precedence. Operators which are listed together have the same precedence.

  • INTERVAL
  • BINARY, COLLATE
  • !
  • - (unary minus), ~ (unary bit inversion)
  • || (string concatenation)
  • ^
  • *, /, DIV, %, MOD
  • -, +
  • >>, <<
  • &
  • |
  • = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
  • BETWEEN, CASE, WHEN, THEN, ELSE
  • NOT
  • &&, AND
  • XOR
  • || (bit or), OR
  • = (assignment), :=

Functions precedence is always higher than operators precedence.

If the HIGH_NOT_PRECEDENCE SQL_MODE is set, NOT has the same precedence as !.

The || operator's precedence, as well as its meaning, depends on the PIPES_AS_CONCAT SQL_MODE flag: if it is on, || can be used to concatenate strings (like the CONCAT() function) and has a higher precedence.

The = operator's precedence depends on the context - it is higher when = is used as a comparison operator.

Parenthesis can be used to modify the operators precedence in an expression.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.