Re: proposal \gcsv

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: proposal \gcsv
Дата
Msg-id 7499.1585698836@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: proposal \gcsv  (Erik Rijkers <er@xs4all.nl>)
Ответы Re: proposal \gcsv
Список pgsql-hackers
I took a look at this proposal, and while I see the value of being
able to do something like this, it seems pretty short-sighted and
non-orthogonal as it stands.  We've already got \gx, which is a wart,
and now this patch wants to add \gfmt which is a different wart of the
same ilk.  What happens if you want to combine them?  Plus we already
had David complaining upthread that he'd like to be able to select
CSV-format suboptions; and now here comes Erik wondering about the
same thing.

It seems to me that this line of development is going to end in a whole
flotilla of \g-something commands that aren't composable and never quite
satisfy the next use-case to come down the pike, so we keep on needing
even more of them.

So I think we really need a way to be able to specify multiple different
\pset subcommands that apply just for the duration of one \g command.
Pavel dismissed that upthread as being too hard, but I think we'd better
try harder.

Plan A:

Consider some syntax along the lines of

\gpset (pset-option-name [pset-option-value]) ... filename

or if you don't like parentheses, choose some other punctuation to wrap
the \pset options in.  I initially thought of square brackets, but I'm
afraid they might be just too darn confusing to document --- how could
you make them distinct from metasyntax square brackets, especially in
plain-ASCII docs?  Also it'd have to be punctuation that's unlikely to
start a file name --- but parens are already reserved in most shells.

Plan B:

Another idea is to break the operation into multiple backslash commands,
where the initial ones set up state that doesn't do anything until the
output command comes along:

\tpset [ pset-option-name [ pset-option-value ] ]

    Sets a "temporary" pset option, which will have effect in the
    next \gpset command; or with no parameters, shows the current set
    of temporary options

\gpset filename

    Execute SQL command and output to filename (or pipe), using the
    pset option set defined by preceding \tpset commands, and reverting
    that option set to all-defaults afterward.

Probably we could think of better terminology than "temporary"
and a better command name than "\tpset", but you get the gist.

Admittedly, "\tpset format csv \gpset filename" is a bit more
verbose than the current proposal of "\gfmt csv filename"
... but we'd have solved the problem once and for all, even
for pset options we've not invented yet.

Plan C:

Probably there are other ways to get there; these are just the
first ideas that came to me.

            regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Anna Akenteva
Дата:
Сообщение: Re: [HACKERS] make async slave to wait for lsn to be replayed
Следующее
От: Tomas Vondra
Дата:
Сообщение: Re: [PATCH] Incremental sort (was: PoC: Partial sort)