psql NUL record and field separator

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: psql NUL record and field separator
Date: 2012-01-14 12:23:49
Message-ID: 1326543829.31492.13.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Inspired by this question http://stackoverflow.com/questions/6857265 I
have implemented a way to set the psql record and field separators to a
zero byte (ASCII NUL character). This can be very useful in shell
scripts to have an unambiguous separator. Other GNU tools such as find,
grep, sort, xargs also support this. So with this you could for example
do

psql --record-separator-zero -At -c 'select something from somewhere' | xargs -0 dosomething

I have thought about two different ways to implement this. Attempt one
was to make the backslash command option parsing zero-byte proof top to
bottom by using PQExpBuffers, so you could then write \R '\000'. But
that turned out to be very invasive and complicated. And worst, you
couldn't use it from the command line, because psql -R '\000' doesn't
work (the octal escape syntax is not used on the command line).

So attempt two, which I present here, is to just have separate syntax to
set the separators to zero bytes. From the command line it would be
--record-separator-zero and --field-separator-zero, and from within psql
it would be \pset recordsep_zero and \pset fieldsep_zero. I don't care
much for the verbosity of this, so I'm still thinking about ways to
abbreviate this. I think the most common use of this would be to set
the record separator from the command line, so we could use a short
option such as -0 or -z for that.

Patch attached. Comments welcome.

Attachment Content-Type Size
psql-nul-sep.patch text/x-patch 14.0 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sergey Konoplev 2012-01-14 12:34:58 pg_statistic, lack of documentation
Previous Message Dimitri Fontaine 2012-01-14 11:44:46 Re: Multithread Query Planner