Re: What is field separator?

From: Tena Sakai <tsakai(at)gallo(dot)ucsf(dot)edu>
To: Gabriele Bartolini <gabriele(dot)bartolini(at)2ndQuadrant(dot)it>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: What is field separator?
Date: 2010-06-01 01:36:41
Message-ID: C829B239.AF3B%tsakai@gallo.ucsf.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi Gabriele,

This isn’t strictly a psql problem, but please humor me.

I can do below from linux prompt:
$ echo "select marker, p, afreq from gallo.fbat_sdsdecode limit 10" | \
> psql -P 'format=unaligned' -P 'fieldsep=,' -t -f - musket
And get:
RS3094315,0.578121,0.735
RS3094315,0.578121,0.265
RS3115850,0.365978,0.251
RS3115850,0.365978,0.749
RS12562034,,0.135
RS12562034,,0.865
RS4475691,0.247133,0.710
RS4475691,0.247133,0.290
RS28705211,,0.725
RS28705211,,0.275

But when I do this:
$ echo "select marker, p, afreq from gallo.fbat_sdsdecode limit 10" | \
> psql -P 'format=unaligned' -P 'fieldsep=\t' -t -f - musket
(here the only change from the previous is the specification of fieldsep)
Then I get:
RS3094315\t0.578121\t0.735
RS3094315\t0.578121\t0.265
RS3115850\t0.365978\t0.251
RS3115850\t0.365978\t0.749
RS12562034\t\t0.135
RS12562034\t\t0.865
RS4475691\t0.247133\t0.710
RS4475691\t0.247133\t0.290
RS28705211\t\t0.725
RS28705211\t\t0.275

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. I can do it from psql
and achieve what I want, but I need to do this from shell level. Any
suggestion what else I can try?

Regards,

Tena Sakai
tsakai(at)gallo(dot)ucsf(dot)edu

On 5/30/10 1:37 AM, "Gabriele Bartolini" <gabriele(dot)bartolini(at)2ndQuadrant(dot)it> wrote:

> Tena Sakai ha scritto:
>> Can somebody please tell me what “|” is called in my example above?
>> And is it possible to change it from “|” to something else for
>> display purpose?
> The field separatore in psql is used only when the format is "unaligned"
> (which does not happen to be default).
>
> In order for it to be effective, you need to type in psql:
>
> \pset format unaligned
> \pset fieldsep '\t'
>
> This will give you an output with columns that are separated by tab.
>
> However, I suggest that you look at the documentation for more options
> and ways to achive the same results:
> http://www.postgresql.org/docs/current/static/app-psql.html
>
> Cheers,
> Gabriele

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Greg Smith 2010-06-01 03:07:57 Re: What is field separator?
Previous Message Jeremy Tunnell 2010-06-01 00:50:16 Re: Strange behaviour: create database hangs (v 8.4.4)