2

When I'm using sqsh in interactive mode, sometimes I like to run my query in the following way so I can get it in a nice csv file:

1> select * from Table where Blah=Blah

2> go -m bcp > /file/name/here

The only problem I have is that using the "-m bcp" option does not give me the column names in the output. Any idea how to get those column names in a "clean" way?

Matt
  • 21
  • 3

3 Answers3

3

There is a CSV display mode in sqsh have you tried that

Tom Depke
  • 83
  • 6
0

Try:

1> select * from Table where Blah=Blah
2> go -m csv > /file/name/here 
Max
  • 1,670
  • 1
  • 12
  • 17
0

Apart from csv style mentioned in other answers, the default horiz style combined with an appropriate value in colsep (not bcp_colsep) will produce separated-output with column names.

1> \set colsep="|"

1> select * from Table where Blah=Blah
2> go
|heading1|heading2|
|--------|--------|
|row1    |col2    |
|row2    |col2    |

However, column values are padded and both the heading-underline and an initial column-separator before the first column are also printed. These could be stripped-off with awk, for example. Perhaps there is no panacea...

A tab character as column separator must be inserted literally with CtrlV-Tab unless a recent sqsh is being used (information from this question: What options are there for the sqsh style "csv" (or anyway to get tab-delimited out)).

crw
  • 655
  • 7
  • 17