psql -F problems

Started by hubert depesz lubaczewskiabout 23 years ago8 messagesbugs
Jump to latest

hi
according to docs -F parameter given to psql is equivalent to \f or
\pset fieldset in psql itself.
this is usually true, but if i'll try to use "tab" as field separator, i
cannot enter it like this:
psql -c "something" -A -t -F '\t'
it just returns fields separated by literally '\t', and not by tab-space
character.
yet, entering the same in psql as \f '\t' works great.
i belive this is just simple ommision in argument parsing, but i belive
it should be corrected to maintain uniform way of communication with
user.

best regards

hubert depesz lubaczewski

--
hubert depesz lubaczewski http://www.depesz.pl/
najwspanialszą rzeczą jaką dało nam nowoczesne społeczeństwo, jest
niesamowita wręcz łatwość unikania kontaktów z nim ...

#2Peter Eisentraut
peter_e@gmx.net
In reply to: hubert depesz lubaczewski (#1)
Re: psql -F problems

Hubert depesz Lubaczewski writes:

this is usually true, but if i'll try to use "tab" as field separator, i
cannot enter it like this:
psql -c "something" -A -t -F '\t'
it just returns fields separated by literally '\t', and not by tab-space
character.

This command is parsed by the shell, so psql cannot do anything about it.
Maybe -F $'\t' works in your shell.

--
Peter Eisentraut peter_e@gmx.net

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#2)
Re: psql -F problems

Peter Eisentraut <peter_e@gmx.net> writes:

Hubert depesz Lubaczewski writes:

this is usually true, but if i'll try to use "tab" as field separator, i
cannot enter it like this:
psql -c "something" -A -t -F '\t'
it just returns fields separated by literally '\t', and not by tab-space
character.

This command is parsed by the shell, so psql cannot do anything about it.

I think Hubert is right: psql is treating command-line -F strings
differently from the argument of \f. Seems like a bug to me too.

regards, tom lane

#4Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#3)
Re: psql -F problems

Hubert depesz Lubaczewski writes:

i belive this kind of information - given from command line - should be
parsed again in psql itself - just like it is parsed when you enter
something at psql prompt.

The command line parser inside psql works pretty much like a Unix shell.
That means quoting and escaping is resolved *before* the arguments are
passed to the command. So when you enter

\f '\t'

then the parser resolves this as two tokens: the first is <backslash><f>
and the second is <tab character>. The \f command and ultimately the
routine that sets the field separator have nothing to do with that.

I believe this design is ok, even though it creates apparent
inconsistencies. If you make it behave like you appear to imagine, then
you need to double-escape certain characters in situations where other
users might not expect it.

--
Peter Eisentraut peter_e@gmx.net

#5Llew Sion Goodstadt
leo.goodstadt@human-anatomy.oxford.ac.uk
In reply to: Peter Eisentraut (#4)
Re: psql -F problems

Most shells allow you to enter in a tab easily. In bash, you need to
type control-V followed
by a tab. I.e. type -F ", followed by the Control-V/tab key sequence and
the closing double quote.

Llew

In reply to: Llew Sion Goodstadt (#5)
Re: psql -F problems

On Mon, Feb 24, 2003 at 11:19:18AM -0000, Llew Sion Goodstadt wrote:

Most shells allow you to enter in a tab easily. In bash, you need to
type control-V followed
by a tab. I.e. type -F ", followed by the Control-V/tab key sequence and
the closing double quote.

i know. i can even do:
psql -c "something" -F "something_weird" | sed 's/something_weird/
/g'
yet - this is inconsistency - between different methods of setting
particular parameter.

depesz

--
hubert depesz lubaczewski http://www.depesz.pl/
i choose to hate people when they're not polite; bruise me; that's allright.
bananafishbones "pow wow"

#7Llew Sion Goodstadt
leo.goodstadt@human-anatomy.oxford.ac.uk
In reply to: hubert depesz lubaczewski (#6)
Re: psql -F problems

Most shells allow you to enter in a tab easily. In bash,

you need to

type control-V followed by a tab. I.e. type -F ", followed by the
Control-V/tab key sequence and the closing double quote.

i know. i can even do:
psql -c "something" -F "something_weird" | sed
's/something_weird/ /g' yet

Very curious now. So how would you enter the tab on the command line for
sed?

depesz

--
hubert depesz lubaczewski
http://www.depesz.pl/

Leo

In reply to: Llew Sion Goodstadt (#7)
Re: psql -F problems

On Thu, Feb 27, 2003 at 05:35:56PM -0000, Llew Sion Goodstadt wrote:

Very curious now. So how would you enter the tab on the command line for
sed?

with ctrl-v ctrl-tab.
YES. i know it is possible to enter tab character itself. and yes - i
can work without it. yet - i still belive that allowing \t in psql and
not allowing \t from commandline is bug and should be fixed.

depesz

--
hubert depesz lubaczewski http://www.depesz.pl/
i choose to hate people when they're not polite; bruise me; that's allright.
bananafishbones "pow wow"