Re: proposal \gcsv - Mailing list pgsql-hackers

From Tom Lane
Subject Re: proposal \gcsv
Date
Msg-id 15550.1585754293@sss.pgh.pa.us
Whole thread Raw
In response to Re: proposal \gcsv  (Vik Fearing <vik@postgresfriends.org>)
Responses Re: proposal \gcsv
List pgsql-hackers
Vik Fearing <vik@postgresfriends.org> writes:
> On 4/1/20 1:53 AM, Tom Lane wrote:
>> Consider some syntax along the lines of
>> \gpset (pset-option-name [pset-option-value]) ... filename

> If parens are going to be required, why don't we just add them to \g?
> TABLE blah \g (format csv) filename

Yeah, if we're willing to assume that nobody uses filenames beginning
with '(', we could just extend \g's syntax rather than adding a new
command.

After sleeping on it, though, I'm liking my Plan B idea better than
Plan A.  Plan B is very clearly implementable without needing surgery
on the backslash-command parser (I didn't look at the lexer to see
what paren-handling would involve, but it might be painful).  And it
doesn't put any new limits on what pset parameters can look like;
Plan A would likely result in some problems if anybody wants to use
parens in future pset options.

I think that maybe the best terminology for Plan B would be to say
that there's an "alternate" formatting parameter set, which is
manipulated by \apset and then used by \ga.

Another thought, bearing in mind the dictum that the only good numbers
in computer science are 0, 1, and N, is to introduce a concept of named
formatting parameter sets, which you'd manipulate with say
    \npset set-name [param-name [param-value]]
and use with
    \gn set-name filename-or-command
A likely usage pattern for that would be to set up a few favorite
formats in your ~/.psqlrc, and then they'd be available to just use
immediately in \gn.  (In this universe, \gn should not destroy or
reset the parameter set it uses.)

This is way beyond what anyone has asked for, so I'm not seriously
proposing that we do it right now, but it might be something to keep
in mind as a possible future direction.  The main thing that it calls
into question is whether we really want \ga to reset the alternate
parameter values after use.  Maybe it'd be better not to --- I can
think of about-equally-likely usage patterns where you would want
that or not.  We could invent an explicit "\apset reset" command
instead of auto-reset.  I could see having a command to copy the
current primary formatting parameters to the alternate area, too.

There's an argument that this is all way too complicated, of course,
and maybe it is.  But considering that we've already had two requests
for things you can't do with \gfmt as it stands, I think the patch
is too simple as it is.

            regards, tom lane



pgsql-hackers by date:

Previous
From: David Steele
Date:
Subject: Re: Verify true root on replicas with amcheck
Next
From: David Steele
Date:
Subject: Re: Online checksums patch - once again