Why the \G in SELECT * FROM table_name\G?

Short Answer
The ubiquitous semicolon command terminator ; is actually shorthand for the \g command, which is in itself shorthand for the go command. The go command is used both historically and currently in other flavours of SQL to submit batches of commands to be compiled and / or interpretted by the server. The \G command seems to inherit it’s characteristic letter from \g, and is capitalised to further indicate a modified behaviour, as described by…
mysql> help
...
\g go Send command to mysql server.
\G ego Send command to mysql server, display result vertically.
...

Longer Answer ( It should really be \E )
Entering help at the mysql prompt lists all the possible mysql commands, including go and ego shown above. The ego command acquires a prepended ‘e’ indicating that this form of the go command also adopts a behaviour that would normally be imposed by invoking mysql with the similar switch mysql -E

From man mysql...
...
--vertical, -E
Print query output rows vertically (one line per column value).
Without this option, you can specify vertical output for individual
statements by terminating them with \G.
...

So why use -E as shorthand for --vertical ?… Because both V, v, and e had already been assigned as switches to other invocation behaviours. The ego command could just have easily used \E as it’s shortcut, but confusingly adopted a capitalised version of the \g command.

In summary…
–vertical >> -E >> ego >> \G …Tada !

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)