How does the precedence of || operator depend on PIPES_AS_CONCAT SQL mode?


As we know that in MySQL by default || operator is a logical OR operator but it depends upon PIPES_AS_CONCAT SQL mode. If PIPES_AS_CONCAT SQL mode is enabled, then || operator works as string concatenation. At that time its precedence would be between ^ and the unary operator. Following example will make it understand −

mysql> Set @C='tutorials';
Query OK, 0 rows affected (0.00 sec)

mysql> Set @D='point';
Query OK, 0 rows affected (0.00 sec)

mysql> Select @C||@D;
+--------+
| @C||@D |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

The result set of the above query shows that || works as OR operator that is why the output is 1 for true.

mysql> Set SQL_MODE = 'PIPES_AS_CONCAT';
Query OK, 0 rows affected (0.10 sec)

After enabling the PIPES_AS_CONCAT SQL mode, || works as the synonym of CONCAT() function i.e. string concatenation function. It is shown in the following result set −

mysql> Select @C||@D;
+----------------+
| @C||@D         |
+----------------+
| tutorialspoint |
+----------------+
1 row in set (0.00 sec)

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

115 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements