What options are there for the sqsh style “csv” (or anyway to get tab-delimited out)

泪湿孤枕 提交于 2019-12-11 04:57:25

问题


With the DB tool sqsh, I want to get the column names and the data tab delimited.

The bcp option does not include the column names.

The csv option includes the column names, but uses comma as the separate (doh). Is there a way to change it?

Currently looking to post-process the file to change the commas to tabs (ignoring the commas within strings...).


回答1:


You can \set colsep="\t" to change the separator for the standard output to tab.

Edit: \t didn’t work (in my cygwin), so I used <CTRL-V><TAB>. That works:

[228] > \set colsep=" " -- Hit CTRL-V then <TAB> here.
[229] > select 'ABC' as STRING, 12 as INT;
    STRING  INT
    ------  -----------
    ABC              12

(1 row affected)



回答2:


Please note that since sqsh version 2.5 it is now possible to assign control characters to some variables like colsep, linesep, bcp_colsep and bcp_rowsep. So the

\set colsep="\t"

should work now properly with sqsh-2.5.



来源:https://stackoverflow.com/questions/17314269/what-options-are-there-for-the-sqsh-style-csv-or-anyway-to-get-tab-delimited

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!