Re: Doc patch on psql output formats - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Doc patch on psql output formats
Date
Msg-id 3679.1543186886@sss.pgh.pa.us
Whole thread Raw
In response to Re: Doc patch on psql output formats  ("Daniel Verite" <daniel@manitou-mail.org>)
Responses Re: Doc patch on psql output formats
List pgsql-hackers
"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

diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index ee88e1c..13d4c57 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3698,7 +3698,6 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
             {"asciidoc", PRINT_ASCIIDOC},
             {"html", PRINT_HTML},
             {"latex", PRINT_LATEX},
-            {"latex-longtable", PRINT_LATEX_LONGTABLE},
             {"troff-ms", PRINT_TROFF_MS},
             {"unaligned", PRINT_UNALIGNED},
             {"wrapped", PRINT_WRAPPED}
@@ -3725,13 +3724,22 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
                     }
                 }
             }
-            if (match_pos < 0)
+            if (match_pos >= 0)
+                popt->topt.format = formats[match_pos].number;
+            else if (pg_strncasecmp("latex-longtable", value, vallen) == 0)
+            {
+                /*
+                 * We must treat latex-longtable specially because latex is a
+                 * prefix of it; if both were in the table above, we'd think
+                 * "latex" is ambiguous.
+                 */
+                popt->topt.format = PRINT_LATEX_LONGTABLE;
+            }
+            else
             {
                 psql_error("\\pset: allowed formats are aligned, asciidoc, html, latex, latex-longtable, troff-ms,
unaligned,wrapped\n"); 
                 return false;
             }
-            else
-                popt->topt.format = formats[match_pos].number;
         }
     }


pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: Continue work on changes to recovery.conf API
Next
From: David Fetter
Date:
Subject: Re: [HACKERS] Time to change pg_regress diffs to unified by default?