Sample Header Ad - 728x90

Why are CASE-expressions in the list documenting operator precedence?

0 votes
1 answer
64 views
In the list here: https://mariadb.com/kb/en/operator-precedence/ case-expressions are put at the same precedence level as BETWEEN, between the NOT operator and the comparison operators. However, case-expressions always begin with CASE and end with END, and all subexpressions are also delimited by the CASE keywords. They're like parenthetical expressions, so I don't understand why case-expressions are on this list. Is there an SQL expression that would be parsed differently if the case-expression precedence was set higher or lower? To give an example, with 2 + 3 * 4, we get different results when parentheses are used in these 2 ways: 2 + (3 * 4) and (2 + 3) * 4. This question is about how it's impossible to do the same with CASE. One can't substitute the use of + for CASE and show 2 different uses of parentheses such that the result differs between them. To compare with other RDBMSes, neither [SQLite](https://sqlite.org/lang_expr.html#operators) nor [PostgreSQL](https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-PRECEDENCE-TABLE) include CASE in their operator precedence lists.
Asked by JoL (289 rep)
Jul 25, 2020, 03:43 PM
Last activity: Jul 31, 2020, 03:43 PM