Recipe 1.21. Suppressing Column Headings in Query Output


Problem

You don't want to include column headings in query output.

Solution

Turn headings off with the appropriate command option. Normally, this is --skip-column-names, but you can also use -ss.

Discussion

Tab-delimited format is convenient for generating datafiles that you can import into other programs. However, the first row of output for each query lists the column headings by default, which may not always be what you want. Suppose that you have a program named summarize that produces various descriptive statistics for a column of numbers. If you're producing output from mysql to be used with this program, you wouldn't want the header row because it would throw off the results. That is, if you ran a command like this, the output would be inaccurate because summarize would count the column heading:

% mysql -e "SELECT arms FROM limbs" cookbook | summarize             

To create output that contains only data values, suppress the column header row with the --skip-column-names option:

% mysql --skip-column-names -e "SELECT arms FROM limbs" cookbook                 | summarize             

You can achieve the same effect as --skip-column-names by specifying the "silent" option (-s or --silent) twice:

% mysql -ss -e "SELECT arms FROM limbs" cookbook | summarize             




MySQL Cookbook
MySQL Cookbook
ISBN: 059652708X
EAN: 2147483647
Year: 2004
Pages: 375
Authors: Paul DuBois

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net