Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
Inspired by this question 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

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: psql-nul-sep.patch
Description: text/x-patch (14.0 KB)


pgsql-hackers by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group