Re: What is field separator?

From: Greg Smith <greg(at)2ndquadrant(dot)com>
To: Tena Sakai <tsakai(at)gallo(dot)ucsf(dot)edu>
Cc: Gabriele Bartolini <gabriele(dot)bartolini(at)2ndQuadrant(dot)it>, "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: What is field separator?
Date: 2010-06-01 03:07:57
Message-ID: 4C04798D.70606@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Tena Sakai wrote:
> $ echo "select marker, p, afreq from gallo.fbat_sdsdecode limit 10" | \
> > psql -P 'format=unaligned' -P 'fieldsep=\t' -t -f - musket
> What's denoted as \t is not a tab character. It is a two character
> sequence backslash followd by a t. I have tried all other possibilities
> such as \\t , "\t", etc that I can think of, but I cannot get an honest to
> god tab character to appear as field separator.

Yeah, that's a tough one. In bash you can use ANSI C quoting to pull
this off:

psql -c "select name,setting from pg_settings limit 1" -d postgres -At
-F $'\t'

See http://wiki.bash-hackers.org/syntax/quoting for more information.
Portability to other shells I'm not sure about.

Note that I did two other things a little differently than your example,
as well as tightening up the abbreviations:

-Putting the command in -c " " is just better all around than piping
into psql using echo. It even works with multi-line input, i.e.:

psql -c "
select 1
"

-Explicitly specifying the database manually using -d makes what's
happening easier to follow than expecting people to know the convention
that the first non-option passed to psql is a database name.

--
Greg Smith 2ndQuadrant US Baltimore, MD
PostgreSQL Training, Services and Support
greg(at)2ndQuadrant(dot)com www.2ndQuadrant.us

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Alvaro Herrera 2010-06-01 03:58:59 Re: What is field separator?
Previous Message Tena Sakai 2010-06-01 01:36:41 Re: What is field separator?