Thread: psql -F

psql -F

From
T E Schmitz
Date:
I have written a shell script to export data:

psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F ' '

Currently, I am using spaces as field separator but what I really want 
is tabs.

How can I specify a TAB character with the -F option?

-- 


Regards,

Tarlika Elisabeth Schmitz


Re: psql -F

From
Alvaro Herrera
Date:
T E Schmitz wrote:
> I have written a shell script to export data:
> 
> psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F ' '
> 
> Currently, I am using spaces as field separator but what I really want 
> is tabs.
> 
> How can I specify a TAB character with the -F option?

This is really a shell question.  On those I know, you'd type ^V <tab>.
(Maybe it would work to use '\t' as well, not sure if psql interprets
that.)

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: psql -F

From
T E Schmitz
Date:
Alvaro Herrera wrote:
> T E Schmitz wrote:
> 
>>I have written a shell script to export data:
>>
>>psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F ' '
>>
>>Currently, I am using spaces as field separator but what I really want 
>>is tabs.
>>
>>How can I specify a TAB character with the -F option?
> 
> 
> This is really a shell question.  On those I know, you'd type ^V <tab>.

True.
Ctrl-V <tab> works fine on the command-line.

> (Maybe it would work to use '\t' as well, not sure if psql interprets
> that.)

Unfortunately, it doesn't. As far as I know -F literally wants a <tab. 
character and how I get it in really is a shell question.

Sorry for having gone off-topic. I was just hoping something like \t 
could be passed, too.

-- 


Regards,

Tarlika Elisabeth Schmitz


Re: psql -F

From
Joe Conway
Date:
T E Schmitz wrote:
> Alvaro Herrera wrote:
> 
>> T E Schmitz wrote:
>>
>>> I have written a shell script to export data:
>>>
>>> psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F ' '
>>>
>>> Currently, I am using spaces as field separator but what I really 
>>> want is tabs.
>>>
>>> How can I specify a TAB character with the -F option?

> Sorry for having gone off-topic. I was just hoping something like \t 
> could be passed, too.
> 

Try:   psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F $'\t'

see:   man bash

HTH,

Joe


Re: psql -F

From
T E Schmitz
Date:
Joe Conway wrote:
> T E Schmitz wrote:
> 
>> Alvaro Herrera wrote:
>>
>>> T E Schmitz wrote:
>>>
>>>> I have written a shell script to export data:
>>>>
>>>> psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F ' '
>>>>
>>>> How can I specify a TAB character with the -F option?
> 
> Try:
>    psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F $'\t'

You're a star - that does the trick!


Regards,

Tarlika Elisabeth Schmitz


Re: psql -F

From
Kazuyuki Maejima
Date:
Joe Conway wrote:
> Try:
>    psql -A -t -U $DBUSER -d $DB -c "$QUERY" -F $'\t'

That's excellent, but please let me post a different way :)
by passing commands from stdin:

#!/bin/sh
cat <<EOT | psql -q -A -t -U $DBUSER -d $DB
\f '\t'
$QUERY
EOT

I think this will work even if your /bin/sh is not bash
(like FreeBSD and NetBSD).

Cheers,
Kazuyuki