Does MySQL have an expanded output flag similar PostgreSQL?


Yes, you can get expanded out in MySQL using the /G, instead of semicolon(;). The syntax is as follows

SELECT *FROM yourTableName\G

Let us first create a table as an example

mysql> create table expandedOutputDemo
   - > (
   - > EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   - > EmployeeName varchar(20),
   - > EmployeeAge int
   - > );
Query OK, 0 rows affected (0.66 sec)

Insert some records in the table using insert command.

The query is as follows

mysql> insert into expandedOutputDemo(EmployeeName,EmployeeAge) values('Larry',27);
Query OK, 1 row affected (0.16 sec)
mysql> insert into expandedOutputDemo(EmployeeName,EmployeeAge) values('Mike',29);
Query OK, 1 row affected (0.12 sec)
mysql> insert into expandedOutputDemo(EmployeeName,EmployeeAge) values('Sam',31);
Query OK, 1 row affected (0.10 sec)
mysql> insert into expandedOutputDemo(EmployeeName,EmployeeAge) values('Bob',24);
Query OK, 1 row affected (0.14 sec)
mysql> insert into expandedOutputDemo(EmployeeName,EmployeeAge) values('Carol',28);
Query OK, 1 row affected (0.09 sec)

Display all records from the table using select statement.

The query is as follows

mysql> select *from expandedOutputDemo;

The following is the output

+------------+--------------+-------------+
| EmployeeId | EmployeeName | EmployeeAge |
+------------+--------------+-------------+
|          1 | Larry        |          27 |
|          2 | Mike         |          29 |
|          3 | Sam          |          31 |
|          4 | Bob          |          24 |
|          5 | Carol        |          28 |
+------------+--------------+-------------+
5 rows in set (0.00 sec)

Here is the query to get expanded output

mysql> select *from expandedOutputDemo\G

The following is the output

*************************** 1. row ***************************
   EmployeeId: 1
 EmployeeName: Larry
  EmployeeAge: 27
*************************** 2. row ***************************
   EmployeeId: 2
 EmployeeName: Mike
  EmployeeAge: 29
*************************** 3. row ***************************
   EmployeeId: 3
 EmployeeName: Sam
  EmployeeAge: 31
*************************** 4. row ***************************
   EmployeeId: 4
 EmployeeName: Bob
  EmployeeAge: 24
*************************** 5. row ***************************
   EmployeeId: 5
 EmployeeName: Carol
  EmployeeAge: 28
5 rows in set (0.00 sec)

Updated on: 30-Jul-2019

70 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements