Thread

Commits

  1. Fix breakage of "\pset format latex".

  2. Make psql's "\pset format" command reject non-unique abbreviations.

  3. Doc: remove claim that all \pset format options are unique in 1 letter.

  4. Reorganize format options of psql in alphabetical order

  1. Doc patch on psql output formats

    Daniel Verite <daniel@manitou-mail.org> — 2018-11-06T14:46:32Z

      Hi,
    
    psql's documentation has this mention about output formats:
     "Unique abbreviations are allowed. (That would mean one letter is enough.)"
    
    but "one letter is enough" is not true since 9.3 that added
    "latex-longtable" sharing the same start as "latex", and then 
    9.5 added "asciidoc" with the same first letter as "aligned".
    
    When a non-unique abbreviation is used, psql uses the first
    match in an arbitrary order defined in do_pset() by
    a cascade of pg_strncasecmp().
    (the recent commit add9182e reorders them alphabetically
    but it turns out that it doesn't change the relative positions
    of  "aligned" / "asciidoc", or "latex" / "latex-longtables"
    so \pset format a and \pset format l will continue to
    select "aligned" and "latex" as before).
    
    Anyway, "Unique abbreviations are allowed" deserves to
    be changed as well.
    
    PFA a doc patch to say simply "Abbreviations are allowed".
    
    
    Best regards,
    -- 
    Daniel Vérité
    PostgreSQL-powered mailer: http://www.manitou-mail.org
    Twitter: @DanielVerite
    
  2. Re: Doc patch on psql output formats

    Tom Lane <tgl@sss.pgh.pa.us> — 2018-11-06T15:03:14Z

    "Daniel Verite" <daniel@manitou-mail.org> writes:
    > psql's documentation has this mention about output formats:
    >  "Unique abbreviations are allowed. (That would mean one letter is enough.)"
    
    > but "one letter is enough" is not true since 9.3 that added
    > "latex-longtable" sharing the same start as "latex", and then 
    > 9.5 added "asciidoc" with the same first letter as "aligned".
    
    Yeah, that text has clearly outstayed its welcome.
    
    > When a non-unique abbreviation is used, psql uses the first
    > match in an arbitrary order defined in do_pset() by
    > a cascade of pg_strncasecmp().
    
    Ugh.  Should we not fix the code so that it complains if there's
    not a unique match?  I would bet that the code was also written
    on the assumption that any abbrevation must be unique.
    
    			regards, tom lane
    
    
    
  3. Re: Doc patch on psql output formats

    Daniel Verite <daniel@manitou-mail.org> — 2018-11-06T17:18:37Z

    	Tom Lane wrote:
    
    > > When a non-unique abbreviation is used, psql uses the first
    > > match in an arbitrary order defined in do_pset() by
    > > a cascade of pg_strncasecmp().
    > 
    > Ugh.  Should we not fix the code so that it complains if there's
    > not a unique match?  I would bet that the code was also written
    > on the assumption that any abbrevation must be unique.
    
    There's a backward compatibility issue, since a script issuing
      \pset format a
    would now fail instead of setting the format to "aligned".
    The doc patch is meant to describe the current behavior.
    
    OTOH if we don't fail with non-unique matches, there is the risk that
    in the future, a new format matching /^a/ will come alphabetically
    before "aligned", and will be picked up instead of "aligned".
    
    In both cases using abbreviations in scripts is not a great
    idea. Anyway I will look into the changes required in do_pset to
    implement the error on multiple matches, if that's the preferred
    behavior.
    
    Best regards,
    -- 
    Daniel Vérité
    PostgreSQL-powered mailer: http://www.manitou-mail.org
    Twitter: @DanielVerite
    
    
    
  4. Re: Doc patch on psql output formats

    Michael Paquier <michael@paquier.xyz> — 2018-11-07T01:56:00Z

    On Tue, Nov 06, 2018 at 06:18:37PM +0100, Daniel Verite wrote:
    > In both cases using abbreviations in scripts is not a great
    > idea. Anyway I will look into the changes required in do_pset to
    > implement the error on multiple matches, if that's the preferred
    > behavior.
    
    You would also break the compatibility of a script using only "a" by
    issuing an error.  Anyway, complaining about an unmatch sounds better
    than a silent failure.
    --
    Michael
    
  5. Re: Doc patch on psql output formats

    Daniel Verite <daniel@manitou-mail.org> — 2018-11-14T17:22:09Z

    	Tom Lane wrote:
    
    > > but "one letter is enough" is not true since 9.3 that added
    > > "latex-longtable" sharing the same start as "latex", and then 
    > > 9.5 added "asciidoc" with the same first letter as "aligned".
    > 
    > Yeah, that text has clearly outstayed its welcome.
    > 
    > > When a non-unique abbreviation is used, psql uses the first
    > > match in an arbitrary order defined in do_pset() by
    > > a cascade of pg_strncasecmp().
    > 
    > Ugh.  Should we not fix the code so that it complains if there's
    > not a unique match?  I would bet that the code was also written
    > on the assumption that any abbrevation must be unique.
    
    Here's a patch making "\pset format" reject ambiguous abbreviations.
    
    
    Best regards,
    -- 
    Daniel Vérité
    PostgreSQL-powered mailer: http://www.manitou-mail.org
    Twitter: @DanielVerite
    
  6. Re: Doc patch on psql output formats

    Tom Lane <tgl@sss.pgh.pa.us> — 2018-11-14T21:41:27Z

    "Daniel Verite" <daniel@manitou-mail.org> writes:
    > 	Tom Lane wrote:
    >> Ugh.  Should we not fix the code so that it complains if there's
    >> not a unique match?  I would bet that the code was also written
    >> on the assumption that any abbrevation must be unique.
    
    > Here's a patch making "\pset format" reject ambiguous abbreviations.
    
    Pushed.  (I simplified the code a bit by using just one state variable,
    and also made the error message more verbose.)
    
    			regards, tom lane
    
    
    
  7. Re: Doc patch on psql output formats

    Daniel Verite <daniel@manitou-mail.org> — 2018-11-15T11:49:28Z

    	Tom Lane wrote:
    
    > Pushed.  (I simplified the code a bit by using just one state variable,
    > and also made the error message more verbose.)
    
    Thanks!
    
    
    Best regards,
    -- 
    Daniel Vérité
    PostgreSQL-powered mailer: http://www.manitou-mail.org
    Twitter: @DanielVerite
    
    
    
  8. Re: Doc patch on psql output formats

    Tom Lane <tgl@sss.pgh.pa.us> — 2018-11-25T23:01:26Z

    "Daniel Verite" <daniel@manitou-mail.org> writes:
    > Tom Lane wrote:
    >> Pushed.  (I simplified the code a bit by using just one state variable,
    >> and also made the error message more verbose.)
    
    > Thanks!
    
    I noticed while poking at the csv patch that we'd outsmarted ourselves
    with this one.  As of HEAD, it's impossible to select latex output format
    at all:
    
    regression=# \pset format latex
    \pset: ambiguous abbreviation "latex" matches both "latex" and "latex-longtable"
    
    We could fix that by adding a special case to accept an exact match
    immediately.  However, that would still leave us in a situation where
    "latex" can never be abbreviated at all, which does not seem very nice
    (not to mention not being backwards-compatible).  Instead I propose
    treating "latex-longtable" as a special case, as attached.  With this
    code, "l", "la", up through "latex" are all accepted as "latex", while
    "latex-" through "latex-longtable" are accepted as "latex-longtable".
    This has less ideological purity than one could wish, but it's backwards
    compatible and arguably a lot more user-friendly than what we'd have
    if we insist on an exact match for "latex".
    
    In future, let's reject any proposal to invent switch or option names
    such that one is a prefix of another.
    
    			regards, tom lane
    
    
  9. Re: Doc patch on psql output formats

    Daniel Verite <daniel@manitou-mail.org> — 2018-11-26T12:00:36Z

    	Tom Lane wrote:
    
    > As of HEAD, it's impossible to select latex output format
    > at all:
    > 
    > regression=# \pset format latex
    > \pset: ambiguous abbreviation "latex" matches both "latex" and
    > "latex-longtable"
    
    Oops!
    
    > We could fix that by adding a special case to accept an exact match
    > immediately.
    
    Personally I would favor that one, but to me the problem is that
    allowing abbreviations doesn't really work well in the long run,
    that is, if new format names are going to appear recurringly in the
    future.
    
    In interactive mode, tab-completion seems good enough (maybe \pset was
    not tab-completed in the past, when abbreviations were initially
    implemented?).
    
    In non-interactive mode, anything abbreviated may clash in the future
    with another format, so there's a forward-compatibility hazzard that
    should motivate to avoid them as well in scripts.
    
    
    Best regards,
    -- 
    Daniel Vérité
    PostgreSQL-powered mailer: http://www.manitou-mail.org
    Twitter: @DanielVerite
    
    
    
  10. Re: Doc patch on psql output formats

    Tom Lane <tgl@sss.pgh.pa.us> — 2018-11-26T14:39:50Z

    "Daniel Verite" <daniel@manitou-mail.org> writes:
    > 	Tom Lane wrote:
    >> As of HEAD, it's impossible to select latex output format
    >> at all:
    >> regression=# \pset format latex
    >> \pset: ambiguous abbreviation "latex" matches both "latex" and
    >> "latex-longtable"
    
    > Oops!
    
    >> We could fix that by adding a special case to accept an exact match
    >> immediately.
    
    > Personally I would favor that one, but to me the problem is that
    > allowing abbreviations doesn't really work well in the long run,
    > that is, if new format names are going to appear recurringly in the
    > future.
    
    Perhaps, but that ship sailed years ago.  I do not think we can or
    should remove the ability to write abbreviations here.  People
    writing scripts are obviously taking a risk of future breakage
    if they abbreviate, but how is it an improvement in their lives
    if we change the risk from "uncertain" to "100%"?
    
    			regards, tom lane