views:

67

answers:

3

Terminating a MySQL query with \G instead of ; will cause MySQL to return the result set in vertical format, which is sometimes easier to read if the number of returned columns is large.

Example:

mysql> SELECT * FROM help_keyword LIMIT 3\G
*************************** 1. row ***************************
help_keyword_id: 0
           name: JOIN
*************************** 2. row ***************************
help_keyword_id: 1
           name: REPEAT
*************************** 3. row ***************************
help_keyword_id: 2
           name: SERIALIZABLE
3 rows in set (0.00 sec)

My question asked out of pure curiosity: Is there any rationale behind choosing the character combination \G?

A: 

It matches the Unix command 'ls' formatting options

Daniel
How does it match the ls formatting options? Do you mean "ls -G"?
knorv
No, -G jsut hides the group. And -g just hides the owner. Not sure what you are thinking of, but -1 shows it in 1 column.
MJB
+2  A: 

My thoughts:

  1. It probably means "go".
  2. Postgresql also uses \g as a statement terminator. Postgresql is older than MySQL so it might have influenced them.

But as I pointed out in my comment to Andriyev's post above, it's actually making the \G uppercase that causes the display to be laid out vertically. Lowercase \g doesn't have that effect, or if it does then the documentation doesn't mention it. (I don't have a MySQL install handy to try it out.)

Nate C-K
"\g" is equivalent to ";" in MySQL
FarmBoy
+1  A: 

Hi

Check this out.

Nate C-K is close with the answer of it being 'Go' i.e. send command to mysql server.

I still can't decipher - how it means a vertical alignment.

cheers

Andriyev
According to that link, it looks like it's actually just when you use a capital (\G) that it displays vertically. So, it's not the choice of letter that makes it align vertically, it's the uppercaseness.
Nate C-K