psql NUL record and field separator
От | Peter Eisentraut |
---|---|
Тема | psql NUL record and field separator |
Дата | |
Msg-id | 1326543829.31492.13.camel@vanquo.pezone.net обсуждение исходный текст |
Ответы |
Re: psql NUL record and field separator
|
Список | 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.
Вложения
В списке pgsql-hackers по дате отправления: