psql and tab-delimited output

From: Abelard Hoffman <abelardhoffman(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: psql and tab-delimited output
Date: 2014-09-06 07:32:58
Message-ID: CACEJHMgrpHXWvYrcCu_WtKZEyeZJ3dzO5GddsL4Y377d7wzbRw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi.

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?

I also considered handling the escaping myself within the SELECT, and then
sticking with the first approach above.

Suggestions?

Thanks.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2014-09-06 09:32:11 Re: psql and tab-delimited output
Previous Message john.tiger 2014-09-05 23:51:51 inserting a text file via json