MySQL statement terminators

There is the semicolon “;” that every one knows, and “g” which is just the same:

mysql > SELECT * FROM wp_links;
mysql > SELECT * FROM wp_links\g

Those are exactly the same, and will produce the same result, here is an example:

mysql> select * from wp_links \g
+---------+-----------------------+--------------+------------+-------------+---------------+------------------+--------------+------------+-------------+---------------------+----------+------------+-----------------------+
| link_id | link_url              | link_name    | link_image | link_target | link_category | link_description | link_visible | link_owner | link_rating | link_updated        | link_rel | link_notes | link_rss              |
+---------+-----------------------+--------------+------------+-------------+---------------+------------------+--------------+------------+-------------+---------------------+----------+------------+-----------------------+
|       1 | http://www.ar-wp.com/ | WP arabic    |            |             |             0 |                  | Y            |          1 |           0 | 0000-00-00 00:00:00 |          |            | http://www.ar-wp.com/ |
+---------+-----------------------+--------------+------------+-------------+---------------+------------------+--------------+------------+-------------+---------------------+----------+------------+-----------------------+
1 row in set (0.01 sec)

\G is another valid statement terminator, it tells MySQL to produce vertical output, this comes in handy when the result has too much columns, here is the same statement again but with the \G terminator:

mysql> select * from wp_links\G
*************************** 1. row ***************************
link_id: 1
link_url: http://www.ar-wp.com/
link_name: WP arabic
link_image:
link_target:
link_category: 0
link_description:
link_visible: Y
link_owner: 1
link_rating: 0
link_updated: 0000-00-00 00:00:00
link_rel:
link_notes:
link_rss: http://www.ar-wp.com/
1 row in set (0.00 sec)

As you can see this is a more user friendly fashion for displaying data.

Leave a Reply

Your email address will not be published. Required fields are marked *