What happens if I use both G and semicolon (;) termination symbol with a single MySQL statement?


As we know that \G option sends the command to MySQL server for execution and with the help of Semicolon (;) MySQL determines the end of the statement. It is also known that both of them have a different format of the result set.

Now, if we will use both of those in MySQL statement then the output would be produced on the basis that which of them is encountered first by MySQL. For others, MySQL will produce an error. It can be understood with the help of the following example −

mysql> Select CURDATE();\G
+------------+
| CURDATE()  |
+------------+
| 2017-11-06 |
+------------+
1 row in set (0.00 sec)
ERROR:
No query specified

In the above MySQL statement, we use a semicolon (;) first and then \G option hence we received the output in tabular format. Afterward, MySQL throws an error as we have not specified any query for \G option.

mysql> Select CURDATE()\G;
*************************** 1. row ***************************
CURDATE(): 2017-11-06
1 row in set (0.00 sec)
    ERROR:
No query specified

In the above MySQL statement, we use \G option first and then a semicolon (;) hence we received the output in vertical format. Afterward, MySQL throws an error as we have not specified any query for semicolon (;).

Updated on: 22-Jun-2020

315 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements