Parenthesis

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

In programming languages manuals, parenthesis are sometimes called precedence operators - this means that they can be used to change the other operators precedence in an expression. The expressions that are written between parenthesis are computed before the expressions that are written outside. Parenthesis must always contain an expression (that is, they cannot be empty), and can be nested.

For example, the following expressions could return different results:

  • NOT a OR b
  • NOT (a OR b)

In the first case, NOT applies to a, so if a is FALSE or b is TRUE, the expression returns TRUE. In the second case, NOT applies to the result of a OR b, so if at least one of a or b is TRUE, the expression is TRUE.

When the precedence of operators is not intuitive, you can use parenthesis to make it immediatly clear for whoever reads the statement.

Syntax errors

If the open parenthesis are more than the closed parenthesis, usually the error looks like this:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '' a
t line 1

Note the empty string.

If the closed parenthesis are more than the open parenthesis, usually the error looks like this:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near ')'
at line 1

Note the quoted closed parenthesis.

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.