From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: psql and tab-delimited output |
Date: | 2014-09-06 09:32:11 |
Message-ID: | luekb5$kgb$1@ger.gmane.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Abelard Hoffman wrote on 06.09.2014 09:32:
> Traditionally, to generate a TSV report, I've simply invoked psql
> with: --no-align --field-separator '\t' --pset footer=off
>
> That works in most cases, except when your column values contain tabs
> themselves.
>
> I know that COPY() will escape tabs (as \t), and we can use that from
> psql with the \copy command, but that does not include a header row
> of the column names.
>
> So, my question is, what's the simplest way to generate tab-escaped
> TSV-formatted reports with the first line containing the list of
> column names?
Do you have to do that using psql or can you use a different tool?
The tool I maintain - SQL Workbench/J - has a command to export tables (or queries) to a wide range of export formats.
WbExport can escape of special characters by using \t, \n etc notation for "control" characters
http://sql-workbench.net/manual/command-export.html
especially
http://sql-workbench.net/manual/command-export.html#text-escape-switch
This can all be done from a shell/batch script if needed.
The tool needs a Java runtime and the Postgres JDBC driver.
Thomas
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2014-09-06 14:28:53 | Re: psql and tab-delimited output |
Previous Message | Abelard Hoffman | 2014-09-06 07:32:58 | psql and tab-delimited output |