Question

When running command-line queries in MySQL you can optionally use '\G' as a statement terminator, and instead of the result set coulmns being listed horizontally across the screen, it will list each column vertically, wich the corresponding data to the right. Is there a way to the same or a similar thing with the DB2 command line utility?

Example regular MySQL result

mysql> select * from tagmap limit 2;
+----+---------+--------+
| id | blog_id | tag_id |
+----+---------+--------+
| 16 |       8 |      1 |
| 17 |       8 |      4 |
+----+---------+--------+

Example Alternate MySQL result:

mysql> select * from tagmap limit 2\G
*************************** 1. row ***************************
     id: 16
blog_id: 8
 tag_id: 1
*************************** 2. row ***************************
     id: 17
blog_id: 8
 tag_id: 4
2 rows in set (0.00 sec)

Obviously, this is much more useful when the columns are large strings, or when there are many columns in a result set, but this demonstrates the formatting better than I can probably explain it.

Was it helpful?

Solution

I don't think such an option is available with the DB2 command line client. See http://www.dbforums.com/showthread.php?t=708079 for some suggestions. For a more general set of information about the DB2 command line client you might check out the IBM DeveloperWorks article DB2's Command Line Processor and Scripting.

OTHER TIPS

DB2 command line utility always displays data in tabular format. i.e. rows horizontally and columns vertically. It does not support any other format like \G statement terminator do for mysql. But yes, you can store column organized data in DB2 tables when DB2_WORKLOAD=ANALYTICS is set.

db2 => connect to coldb

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.5
 SQL authorization ID   = BIMALJHA
 Local database alias   = COLDB

db2 => create table testtable (c1 int, c2 varchar(10)) organize by column
DB20000I  The SQL command completed successfully.
db2 => insert into testtable values (2, 'bimal'),(3, 'kumar')
DB20000I  The SQL command completed successfully.
db2 => select * from testtable

C1          C2        
----------- ----------
          2 bimal     
          3 kumar     

  2 record(s) selected.

db2 => terminate
DB20000I  The TERMINATE command completed successfully.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top