]> granicus.if.org Git - postgresql/blobdiff - src/bin/psql/help.c
Teach psql to display the comments on conversions and domains.
[postgresql] / src / bin / psql / help.c
index 22ba847a9bcd02c08d8bc347f307259fe4d6d1e0..b99ba3acfb531868e31f44a46638ffb94f17db84 100644 (file)
@@ -1,14 +1,12 @@
 /*
  * psql - the PostgreSQL interactive terminal
  *
- * Copyright (c) 2000-2008, PostgreSQL Global Development Group
+ * Copyright (c) 2000-2011, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.124 2008/03/29 19:40:12 tgl Exp $
+ * src/bin/psql/help.c
  */
 #include "postgres_fe.h"
 
-#include <signal.h>
-
 #ifndef WIN32
 #ifdef HAVE_PWD_H
 #include <pwd.h>                               /* for getpwuid() */
@@ -27,8 +25,6 @@
 #include <termios.h>
 #endif
 
-#include "pqsignal.h"
-
 #include "common.h"
 #include "help.h"
 #include "input.h"
@@ -83,70 +79,72 @@ usage(void)
 #endif   /* WIN32 */
        }
 
-/* >>> If this " is the start of the string then it ought to end there to fit in 80 columns >> " */
-       printf(_("This is psql %s, the PostgreSQL interactive terminal.\n\n"),
-                  PG_VERSION);
-       puts(_("Usage:"));
-       puts(_("  psql [OPTIONS]... [DBNAME [USERNAME]]\n"));
+       printf(_("psql is the PostgreSQL interactive terminal.\n\n"));
+       printf(_("Usage:\n"));
+       printf(_("  psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
 
-       puts(_("General options:"));
+       printf(_("General options:\n"));
        /* Display default database */
        env = getenv("PGDATABASE");
        if (!env)
                env = user;
-       printf(_("  -d DBNAME       specify database name to connect to (default: \"%s\")\n"), env);
-       puts(_("  -c COMMAND      run only single command (SQL or internal) and exit"));
-       puts(_("  -f FILENAME     execute commands from file, then exit"));
-       puts(_("  -1 (\"one\")      execute command file as a single transaction"));
-       puts(_("  -l              list available databases, then exit"));
-       puts(_("  -v NAME=VALUE   set psql variable NAME to VALUE"));
-       puts(_("  -X              do not read startup file (~/.psqlrc)"));
-       puts(_("  --help          show this help, then exit"));
-       puts(_("  --version       output version information, then exit"));
-
-       puts(_("\nInput and output options:"));
-       puts(_("  -a              echo all input from script"));
-       puts(_("  -e              echo commands sent to server"));
-       puts(_("  -E              display queries that internal commands generate"));
-       puts(_("  -q              run quietly (no messages, only query output)"));
-       puts(_("  -o FILENAME     send query results to file (or |pipe)"));
-       puts(_("  -n              disable enhanced command line editing (readline)"));
-       puts(_("  -s              single-step mode (confirm each query)"));
-       puts(_("  -S              single-line mode (end of line terminates SQL command)"));
-       puts(_("  -L FILENAME     send session log to file"));
-
-       puts(_("\nOutput format options:"));
-       puts(_("  -A              unaligned table output mode (-P format=unaligned)"));
-       puts(_("  -H              HTML table output mode (-P format=html)"));
-       puts(_("  -t              print rows only (-P tuples_only)"));
-       puts(_("  -T TEXT         set HTML table tag attributes (width, border) (-P tableattr=)"));
-       puts(_("  -x              turn on expanded table output (-P expanded)"));
-       puts(_("  -P VAR[=ARG]    set printing option VAR to ARG (see \\pset command)"));
-       printf(_("  -F STRING       set field separator (default: \"%s\") (-P fieldsep=)\n"),
+       printf(_("  -c, --command=COMMAND    run only single command (SQL or internal) and exit\n"));
+       printf(_("  -d, --dbname=DBNAME      database name to connect to (default: \"%s\")\n"), env);
+       printf(_("  -f, --file=FILENAME      execute commands from file, then exit\n"));
+       printf(_("  -l, --list               list available databases, then exit\n"));
+       printf(_("  -v, --set=, --variable=NAME=VALUE\n"
+                        "                           set psql variable NAME to VALUE\n"));
+       printf(_("  -X, --no-psqlrc          do not read startup file (~/.psqlrc)\n"));
+       printf(_("  -1 (\"one\"), --single-transaction\n"
+                        "                           execute command file as a single transaction\n"));
+       printf(_("  --help                   show this help, then exit\n"));
+       printf(_("  --version                output version information, then exit\n"));
+
+       printf(_("\nInput and output options:\n"));
+       printf(_("  -a, --echo-all           echo all input from script\n"));
+       printf(_("  -e, --echo-queries       echo commands sent to server\n"));
+       printf(_("  -E, --echo-hidden        display queries that internal commands generate\n"));
+       printf(_("  -L, --log-file=FILENAME  send session log to file\n"));
+       printf(_("  -n, --no-readline        disable enhanced command line editing (readline)\n"));
+       printf(_("  -o, --output=FILENAME    send query results to file (or |pipe)\n"));
+       printf(_("  -q, --quiet              run quietly (no messages, only query output)\n"));
+       printf(_("  -s, --single-step        single-step mode (confirm each query)\n"));
+       printf(_("  -S, --single-line        single-line mode (end of line terminates SQL command)\n"));
+
+       printf(_("\nOutput format options:\n"));
+       printf(_("  -A, --no-align           unaligned table output mode\n"));
+       printf(_("  -F, --field-separator=STRING\n"
+          "                           set field separator (default: \"%s\")\n"),
                   DEFAULT_FIELD_SEP);
-       puts(_("  -R STRING       set record separator (default: newline) (-P recordsep=)"));
-
-       puts(_("\nConnection options:"));
+       printf(_("  -H, --html               HTML table output mode\n"));
+       printf(_("  -P, --pset=VAR[=ARG]     set printing option VAR to ARG (see \\pset command)\n"));
+       printf(_("  -R, --record-separator=STRING\n"
+       "                           set record separator (default: newline)\n"));
+       printf(_("  -t, --tuples-only        print rows only\n"));
+       printf(_("  -T, --table-attr=TEXT    set HTML table tag attributes (e.g., width, border)\n"));
+       printf(_("  -x, --expanded           turn on expanded table output\n"));
+
+       printf(_("\nConnection options:\n"));
        /* Display default host */
        env = getenv("PGHOST");
-       printf(_("  -h HOSTNAME     database server host or socket directory (default: \"%s\")\n"),
+       printf(_("  -h, --host=HOSTNAME      database server host or socket directory (default: \"%s\")\n"),
                   env ? env : _("local socket"));
        /* Display default port */
        env = getenv("PGPORT");
-       printf(_("  -p PORT         database server port (default: \"%s\")\n"),
+       printf(_("  -p, --port=PORT          database server port (default: \"%s\")\n"),
                   env ? env : DEF_PGPORT_STR);
        /* Display default user */
        env = getenv("PGUSER");
        if (!env)
                env = user;
-       printf(_("  -U NAME         database user name (default: \"%s\")\n"), env);
-       puts(_("  -W              force password prompt (should happen automatically)"));
-
-       puts(_(
-                  "\nFor more information, type \"\\?\" (for internal commands) or \"\\help\"\n"
-         "(for SQL commands) from within psql, or consult the psql section in\n"
-                  "the PostgreSQL documentation.\n\n"
-                  "Report bugs to <pgsql-bugs@postgresql.org>."));
+       printf(_("  -U, --username=USERNAME  database user name (default: \"%s\")\n"), env);
+       printf(_("  -w, --no-password        never prompt for password\n"));
+       printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
+
+       printf(_("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
+                        "commands) from within psql, or consult the psql section in the PostgreSQL\n"
+                        "documentation.\n\n"));
+       printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
 }
 
 
@@ -160,112 +158,123 @@ slashUsage(unsigned short int pager)
 {
        FILE       *output;
 
-       output = PageOutput(69, pager);
+       output = PageOutput(93, pager);
 
        /* if you add/remove a line here, change the row count above */
 
-       /*
-        * if this " is the start of the string then it ought to end there to fit
-        * in 80 columns >> "
-        */
        fprintf(output, _("General\n"));
-       fprintf(output, _("  \\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]\n"
-                       "                 connect to new database (currently \"%s\")\n"),
-                       PQdb(pset.db));
-       fprintf(output, _("  \\cd [DIR]      change the current working directory\n"));
-       fprintf(output, _("  \\copyright     show PostgreSQL usage and distribution terms\n"));
-       fprintf(output, _("  \\encoding [ENCODING]\n"
-                                         "                 show or set client encoding\n"));
-       fprintf(output, _("  \\h [NAME]      help on syntax of SQL commands, * for all commands\n"));
-       fprintf(output, _("  \\prompt [TEXT] NAME\n"
-                                "                 prompt user to set internal variable\n"));
-       fprintf(output, _("  \\password [USERNAME]\n"
-                                "                 securely change the password for a user\n"));
-       fprintf(output, _("  \\q             quit psql\n"));
-       fprintf(output, _("  \\set [NAME [VALUE]]\n"
-                                         "                 set internal variable, or list all if no parameters\n"));
-       fprintf(output, _("  \\timing        toggle timing of commands (currently %s)\n"),
-                       ON(pset.timing));
-       fprintf(output, _("  \\unset NAME    unset (delete) internal variable\n"));
-       fprintf(output, _("  \\! [COMMAND]   execute command in shell or start interactive shell\n"));
+       fprintf(output, _("  \\copyright             show PostgreSQL usage and distribution terms\n"));
+       fprintf(output, _("  \\g [FILE] or ;         execute query (and send results to file or |pipe)\n"));
+       fprintf(output, _("  \\h [NAME]              help on syntax of SQL commands, * for all commands\n"));
+       fprintf(output, _("  \\q                     quit psql\n"));
        fprintf(output, "\n");
 
        fprintf(output, _("Query Buffer\n"));
-       fprintf(output, _("  \\e [FILE]      edit the query buffer (or file) with external editor\n"));
-       fprintf(output, _("  \\g [FILE]      send query buffer to server (and results to file or |pipe)\n"));
-       fprintf(output, _("  \\p             show the contents of the query buffer\n"));
-       fprintf(output, _("  \\r             reset (clear) the query buffer\n"));
+       fprintf(output, _("  \\e [FILE] [LINE]       edit the query buffer (or file) with external editor\n"));
+       fprintf(output, _("  \\ef [FUNCNAME [LINE]]  edit function definition with external editor\n"));
+       fprintf(output, _("  \\p                     show the contents of the query buffer\n"));
+       fprintf(output, _("  \\r                     reset (clear) the query buffer\n"));
 #ifdef USE_READLINE
-       fprintf(output, _("  \\s [FILE]      display history or save it to file\n"));
+       fprintf(output, _("  \\s [FILE]              display history or save it to file\n"));
 #endif
-       fprintf(output, _("  \\w FILE        write query buffer to file\n"));
+       fprintf(output, _("  \\w FILE                write query buffer to file\n"));
        fprintf(output, "\n");
 
        fprintf(output, _("Input/Output\n"));
-       fprintf(output, _("  \\echo [STRING] write string to standard output\n"));
-       fprintf(output, _("  \\i FILE        execute commands from file\n"));
-       fprintf(output, _("  \\o [FILE]      send all query results to file or |pipe\n"));
-       fprintf(output, _("  \\qecho [STRING]\n"
-               "                 write string to query output stream (see \\o)\n"));
+       fprintf(output, _("  \\copy ...              perform SQL COPY with data stream to the client host\n"));
+       fprintf(output, _("  \\echo [STRING]         write string to standard output\n"));
+       fprintf(output, _("  \\i FILE                execute commands from file\n"));
+       fprintf(output, _("  \\ir FILE               as \\i, but relative to location of current script\n"));
+       fprintf(output, _("  \\o [FILE]              send all query results to file or |pipe\n"));
+       fprintf(output, _("  \\qecho [STRING]        write string to query output stream (see \\o)\n"));
        fprintf(output, "\n");
 
        fprintf(output, _("Informational\n"));
-       fprintf(output, _("  \\d [NAME]      describe table, index, sequence, or view\n"));
-       fprintf(output, _("  \\d{t|i|s|v|S} [PATTERN] (add \"+\" for more detail)\n"
-       "                 list tables/indexes/sequences/views/system tables\n"));
-       fprintf(output, _("  \\da [PATTERN]  list aggregate functions\n"));
-       fprintf(output, _("  \\db [PATTERN]  list tablespaces (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\dc [PATTERN]  list conversions\n"));
-       fprintf(output, _("  \\dC            list casts\n"));
-       fprintf(output, _("  \\dd [PATTERN]  show comment for object\n"));
-       fprintf(output, _("  \\dD [PATTERN]  list domains\n"));
-       fprintf(output, _("  \\df [PATTERN]  list functions (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\dF [PATTERN]  list text search configurations (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\dFd [PATTERN] list text search dictionaries (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\dFt [PATTERN] list text search templates\n"));
-       fprintf(output, _("  \\dFp [PATTERN] list text search parsers (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\dg [PATTERN]  list roles (groups)\n"));
-       fprintf(output, _("  \\dn [PATTERN]  list schemas (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\do [NAME]     list operators\n"));
-       fprintf(output, _("  \\dl            list large objects, same as \\lo_list\n"));
-       fprintf(output, _("  \\dp [PATTERN]  list table, view, and sequence access privileges\n"));
-       fprintf(output, _("  \\dT [PATTERN]  list data types (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\du [PATTERN]  list roles (users)\n"));
-       fprintf(output, _("  \\l             list all databases (add \"+\" for more detail)\n"));
-       fprintf(output, _("  \\z [PATTERN]   list table, view, and sequence access privileges (same as \\dp)\n"));
+       fprintf(output, _("  (options: S = show system objects, + = additional detail)\n"));
+       fprintf(output, _("  \\d[S+]                 list tables, views, and sequences\n"));
+       fprintf(output, _("  \\d[S+]  NAME           describe table, view, sequence, or index\n"));
+       fprintf(output, _("  \\da[S]  [PATTERN]      list aggregates\n"));
+       fprintf(output, _("  \\db[+]  [PATTERN]      list tablespaces\n"));
+       fprintf(output, _("  \\dc[S+] [PATTERN]      list conversions\n"));
+       fprintf(output, _("  \\dC[+]  [PATTERN]      list casts\n"));
+       fprintf(output, _("  \\dd[S]  [PATTERN]      show comments on objects\n"));
+       fprintf(output, _("  \\ddp    [PATTERN]      list default privileges\n"));
+       fprintf(output, _("  \\dD[S+] [PATTERN]      list domains\n"));
+       fprintf(output, _("  \\det[+] [PATTERN]      list foreign tables\n"));
+       fprintf(output, _("  \\des[+] [PATTERN]      list foreign servers\n"));
+       fprintf(output, _("  \\deu[+] [PATTERN]      list user mappings\n"));
+       fprintf(output, _("  \\dew[+] [PATTERN]      list foreign-data wrappers\n"));
+       fprintf(output, _("  \\df[antw][S+] [PATRN]  list [only agg/normal/trigger/window] functions\n"));
+       fprintf(output, _("  \\dF[+]  [PATTERN]      list text search configurations\n"));
+       fprintf(output, _("  \\dFd[+] [PATTERN]      list text search dictionaries\n"));
+       fprintf(output, _("  \\dFp[+] [PATTERN]      list text search parsers\n"));
+       fprintf(output, _("  \\dFt[+] [PATTERN]      list text search templates\n"));
+       fprintf(output, _("  \\dg[+]  [PATTERN]      list roles\n"));
+       fprintf(output, _("  \\di[S+] [PATTERN]      list indexes\n"));
+       fprintf(output, _("  \\dl                    list large objects, same as \\lo_list\n"));
+       fprintf(output, _("  \\dL[S+] [PATTERN]      list procedural languages\n"));
+       fprintf(output, _("  \\dn[S+] [PATTERN]      list schemas\n"));
+       fprintf(output, _("  \\do[S]  [PATTERN]      list operators\n"));
+       fprintf(output, _("  \\dO[S+] [PATTERN]      list collations\n"));
+       fprintf(output, _("  \\dp     [PATTERN]      list table, view, and sequence access privileges\n"));
+       fprintf(output, _("  \\drds [PATRN1 [PATRN2]] list per-database role settings\n"));
+       fprintf(output, _("  \\ds[S+] [PATTERN]      list sequences\n"));
+       fprintf(output, _("  \\dt[S+] [PATTERN]      list tables\n"));
+       fprintf(output, _("  \\dT[S+] [PATTERN]      list data types\n"));
+       fprintf(output, _("  \\du[+]  [PATTERN]      list roles\n"));
+       fprintf(output, _("  \\dv[S+] [PATTERN]      list views\n"));
+       fprintf(output, _("  \\dE[S+] [PATTERN]      list foreign tables\n"));
+       fprintf(output, _("  \\dx[+]  [PATTERN]      list extensions\n"));
+       fprintf(output, _("  \\l[+]                  list all databases\n"));
+       fprintf(output, _("  \\sf[+] FUNCNAME        show a function's definition\n"));
+       fprintf(output, _("  \\z      [PATTERN]      same as \\dp\n"));
        fprintf(output, "\n");
 
        fprintf(output, _("Formatting\n"));
-       fprintf(output, _("  \\a             toggle between unaligned and aligned output mode\n"));
-       fprintf(output, _("  \\C [STRING]    set table title, or unset if none\n"));
-       fprintf(output, _("  \\f [STRING]    show or set field separator for unaligned query output\n"));
-       fprintf(output, _("  \\H             toggle HTML output mode (currently %s)\n"),
+       fprintf(output, _("  \\a                     toggle between unaligned and aligned output mode\n"));
+       fprintf(output, _("  \\C [STRING]            set table title, or unset if none\n"));
+       fprintf(output, _("  \\f [STRING]            show or set field separator for unaligned query output\n"));
+       fprintf(output, _("  \\H                     toggle HTML output mode (currently %s)\n"),
                        ON(pset.popt.topt.format == PRINT_HTML));
-       fprintf(output, _("  \\pset NAME [VALUE]\n"
-                                         "                 set table output option\n"
-                                         "                 (NAME := {format|border|expanded|fieldsep|footer|null|\n"
-                                         "                 numericlocale|recordsep|tuples_only|title|tableattr|pager})\n"));
-       fprintf(output, _("  \\t             show only rows (currently %s)\n"),
+       fprintf(output, _("  \\pset NAME [VALUE]     set table output option\n"
+                                         "                         (NAME := {format|border|expanded|fieldsep|footer|null|\n"
+                                         "                         numericlocale|recordsep|tuples_only|title|tableattr|pager})\n"));
+       fprintf(output, _("  \\t [on|off]            show only rows (currently %s)\n"),
                        ON(pset.popt.topt.tuples_only));
-       fprintf(output, _("  \\T [STRING]    set HTML <table> tag attributes, or unset if none\n"));
-       fprintf(output, _("  \\x             toggle expanded output (currently %s)\n"),
+       fprintf(output, _("  \\T [STRING]            set HTML <table> tag attributes, or unset if none\n"));
+       fprintf(output, _("  \\x [on|off]            toggle expanded output (currently %s)\n"),
                        ON(pset.popt.topt.expanded));
        fprintf(output, "\n");
 
-       fprintf(output, _("Copy, Large Object\n"));
-       fprintf(output, _("  \\copy ...      perform SQL COPY with data stream to the client host\n"));
+       fprintf(output, _("Connection\n"));
+       fprintf(output, _("  \\c[onnect] [DBNAME|- USER|- HOST|- PORT|-]\n"
+       "                         connect to new database (currently \"%s\")\n"),
+                       PQdb(pset.db));
+       fprintf(output, _("  \\encoding [ENCODING]   show or set client encoding\n"));
+       fprintf(output, _("  \\password [USERNAME]   securely change the password for a user\n"));
+       fprintf(output, _("  \\conninfo              display information about current connection\n"));
+       fprintf(output, "\n");
+
+       fprintf(output, _("Operating System\n"));
+       fprintf(output, _("  \\cd [DIR]              change the current working directory\n"));
+       fprintf(output, _("  \\timing [on|off]       toggle timing of commands (currently %s)\n"),
+                       ON(pset.timing));
+       fprintf(output, _("  \\! [COMMAND]           execute command in shell or start interactive shell\n"));
+       fprintf(output, "\n");
+
+       fprintf(output, _("Variables\n"));
+       fprintf(output, _("  \\prompt [TEXT] NAME    prompt user to set internal variable\n"));
+       fprintf(output, _("  \\set [NAME [VALUE]]    set internal variable, or list all if no parameters\n"));
+       fprintf(output, _("  \\unset NAME            unset (delete) internal variable\n"));
+       fprintf(output, "\n");
+
+       fprintf(output, _("Large Objects\n"));
        fprintf(output, _("  \\lo_export LOBOID FILE\n"
                                          "  \\lo_import FILE [COMMENT]\n"
                                          "  \\lo_list\n"
-                                         "  \\lo_unlink LOBOID    large object operations\n"));
+                                         "  \\lo_unlink LOBOID      large object operations\n"));
 
-       if (output != stdout)
-       {
-               pclose(output);
-#ifndef WIN32
-               pqsignal(SIGPIPE, SIG_DFL);
-#endif
-       }
+       ClosePager(output);
 }
 
 
@@ -273,6 +282,7 @@ slashUsage(unsigned short int pager)
 /*
  * helpSQL -- help with SQL commands
  *
+ * Note: we assume caller removed any trailing spaces in "topic".
  */
 void
 helpSQL(const char *topic, unsigned short int pager)
@@ -311,7 +321,7 @@ helpSQL(const char *topic, unsigned short int pager)
                for (i = 0; i < nrows; i++)
                {
                        fprintf(output, "  ");
-                       for (j = 0; j < ncolumns-1; j++)
+                       for (j = 0; j < ncolumns - 1; j++)
                                fprintf(output, "%-*s",
                                                QL_MAX_CMD_LEN + 1,
                                                VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd));
@@ -321,14 +331,7 @@ helpSQL(const char *topic, unsigned short int pager)
                        fputc('\n', output);
                }
 
-               /* Only close if we used the pager */
-               if (output != stdout)
-               {
-                       pclose(output);
-#ifndef WIN32
-                       pqsignal(SIGPIPE, SIG_DFL);
-#endif
-               }
+               ClosePager(output);
        }
        else
        {
@@ -336,23 +339,21 @@ helpSQL(const char *topic, unsigned short int pager)
                                        j,
                                        x = 0;
                bool            help_found = false;
-               FILE       *output;
+               FILE       *output = NULL;
                size_t          len,
                                        wordlen;
                int                     nl_count = 0;
-               const char *ch;
 
-               /* User gets two chances: exact match, then the first word */
-
-               /* First pass : strip trailing spaces and semicolons */
+               /*
+                * We first try exact match, then first + second words, then first
+                * word only.
+                */
                len = strlen(topic);
-               while (topic[len - 1] == ' ' || topic[len - 1] == ';')
-                       len--;
 
-               for (x = 1; x <= 3; x++)        /* Three chances to guess that word... */
+               for (x = 1; x <= 3; x++)
                {
                        if (x > 1)                      /* Nothing on first pass - try the opening
-                                                                * words */
+                                                                * word(s) */
                        {
                                wordlen = j = 1;
                                while (topic[j] != ' ' && j++ < len)
@@ -365,7 +366,8 @@ helpSQL(const char *topic, unsigned short int pager)
                                }
                                if (wordlen >= len)             /* Don't try again if the same word */
                                {
-                                       output = PageOutput(nl_count, pager);
+                                       if (!output)
+                                               output = PageOutput(nl_count, pager);
                                        break;
                                }
                                len = wordlen;
@@ -377,30 +379,33 @@ helpSQL(const char *topic, unsigned short int pager)
                                if (pg_strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||
                                        strcmp(topic, "*") == 0)
                                {
-                                       nl_count += 5;
-                                       for (ch = QL_HELP[i].syntax; *ch != '\0'; ch++)
-                                               if (*ch == '\n')
-                                                       nl_count++;
+                                       nl_count += 5 + QL_HELP[i].nl_count;
+
                                        /* If we have an exact match, exit.  Fixes \h SELECT */
                                        if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0)
                                                break;
                                }
                        }
 
-                       output = PageOutput(nl_count, pager);
+                       if (!output)
+                               output = PageOutput(nl_count, pager);
 
                        for (i = 0; QL_HELP[i].cmd; i++)
                        {
                                if (pg_strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||
                                        strcmp(topic, "*") == 0)
                                {
+                                       PQExpBufferData buffer;
+
+                                       initPQExpBuffer(&buffer);
+                                       QL_HELP[i].syntaxfunc(&buffer);
                                        help_found = true;
                                        fprintf(output, _("Command:     %s\n"
                                                                          "Description: %s\n"
                                                                          "Syntax:\n%s\n\n"),
                                                        QL_HELP[i].cmd,
                                                        _(QL_HELP[i].help),
-                                                       _(QL_HELP[i].syntax));
+                                                       buffer.data);
                                        /* If we have an exact match, exit.  Fixes \h SELECT */
                                        if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0)
                                                break;
@@ -411,16 +416,9 @@ helpSQL(const char *topic, unsigned short int pager)
                }
 
                if (!help_found)
-                       fprintf(output, _("No help available for \"%-.*s\".\nTry \\h with no arguments to see available help.\n"), (int) len, topic);
+                       fprintf(output, _("No help available for \"%s\".\nTry \\h with no arguments to see available help.\n"), topic);
 
-               /* Only close if we used the pager */
-               if (output != stdout)
-               {
-                       pclose(output);
-#ifndef WIN32
-                       pqsignal(SIGPIPE, SIG_DFL);
-#endif
-               }
+               ClosePager(output);
        }
 }
 
@@ -430,24 +428,23 @@ void
 print_copyright(void)
 {
        puts(
-                "PostgreSQL Data Base Management System\n\n"
-                "Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group\n\n"
-                "This software is based on Postgres95, formerly known as Postgres, which\n"
-                "contains the following notice:\n\n"
-       "Portions Copyright(c) 1994, Regents of the University of California\n\n"
+                "PostgreSQL Database Management System\n"
+                "(formerly known as Postgres, then as Postgres95)\n\n"
+                "Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group\n\n"
+                "Portions Copyright (c) 1994, The Regents of the University of California\n\n"
        "Permission to use, copy, modify, and distribute this software and its\n"
                 "documentation for any purpose, without fee, and without a written agreement\n"
-                "is hereby granted, provided that the above copyright notice and this paragraph\n"
-                "and the following two paragraphs appear in all copies.\n\n"
+        "is hereby granted, provided that the above copyright notice and this\n"
+          "paragraph and the following two paragraphs appear in all copies.\n\n"
                 "IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR\n"
-                "DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST\n"
-                "PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF\n"
-                "THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\n"
-                "DAMAGE.\n\n"
-                "THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,\n"
-                "BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n"
-                "PARTICULAR PURPOSE.THE SOFTWARE PROVIDED HEREUNDER IS ON AN \"AS IS\" BASIS,\n"
-                "AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,\n"
-                "SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
+                "DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING\n"
+                "LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS\n"
+                "DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE\n"
+                "POSSIBILITY OF SUCH DAMAGE.\n\n"
+         "THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,\n"
+                "INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\n"
+                "AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS\n"
+                "ON AN \"AS IS\" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO\n"
+       "PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.\n"
                );
 }