[Js-mysql] Operator Precedence

Source: Internet
Author: User

The MySQL official documentation provides operators with the following precedence:

Operator Precedences is shown in the following list, from highest precedence to the lowest. Operators that is shown together on a line has the the same precedence.

1 INTERVAL2 BINARY, COLLATE3!4-(unary minus), ~(unary bit inversion)5^6*,/, DIV,%, MOD7-, +8<<, >>9&Ten| One= (comparison), <=>, >=,;, <=, <, <>,! =, is, like, REGEXP, in A between, case, if, then, ELSE -  not -And, && the XOR -OR, | | -= (Assignment),: =

The precedence of=Depends on whether it is used as a comparison operator (=) or as an assignment operator (=). When used as a comparison operator, it had the same precedence as<=>,>=,>,<=,<,<>,!=,IS,LIKE,REGEXP, andIN. When used as a assignment operator, it has the same precedence as:=. Section 13.7.4.1, "SET Syntax for Variable assignment", and sections 9.4, "user-defined Variables", explain how MySQL deter Mines which interpretation of=should apply.

For operators this occur at the same-precedence level within a expression, evaluation proceeds left-to-right, with the ex Ception that assignments the evaluate right to the left.

The meaning of some operators depends on the SQL mode:

    • By default, is || a logical OR operator. PIPES_AS_CONCATwith enabled, was || string concatenation, with a precedence between and the ^ unary operators.

    • By default, have ! a higher precedence than NOT . HIGH_NOT_PRECEDENCEwith enabled, and has the ! NOT same precedence.

See section 5.1.8, "Server SQL Modes".

The precedence of operators determines the order of evaluation of terms in an expression. To override the this order and the group terms explicitly, use parentheses. For example:

1 mysql> SELECT 1+2*3; 2         -73 mysql> SELECT (1+2); 4         9

[Js-mysql] Operator Precedence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.