Re: [HACKERS] Version number in psql banner - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: [HACKERS] Version number in psql banner
Date
Msg-id 200509030039.j830dqd16598@candle.pha.pa.us
Whole thread Raw
List pgsql-patches
Tom Lane wrote:
> Darcy Buskermolen <darcy@wavefire.com> writes:
> > Yes I've seen the same frustration from users,  I think the banner should say
> > something along the lines of "psql client version foo connected to server bar
> > version sfoo"
>
> That seems overly verbose, particularly in the normal case where the
> versions are indeed the same.  I could live with seeing a display like
> that when the versions are different.
>
> The other question is what counts as "different" --- do we want to
> complain like this if the minor versions are different?

I updated the patch.  This gives psql three output displays on startup:

full match:

    Welcome to psql 8.1beta1, the PostgreSQL interactive terminal.

major match:

    Welcome to psql, the PostgreSQL interactive terminal.
    psql version 8.19, server version 8.1

and non-major match:

    WARNING:  You are connected to a server with major version 8.1,
    but your psql client is major version 8.2.  Informational backslash
    commands, like \d, might not work properly.

    Welcome to psql, the PostgreSQL interactive terminal.
    psql version 8.29, server version 8.1

Patch attached.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/bin/psql/startup.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/startup.c,v
retrieving revision 1.120
diff -c -c -r1.120 startup.c
*** src/bin/psql/startup.c    25 Jul 2005 17:17:41 -0000    1.120
--- src/bin/psql/startup.c    3 Sep 2005 00:34:52 -0000
***************
*** 312,324 ****

          if (!QUIET() && !pset.notty)
          {
!             printf(_("Welcome to %s %s, the PostgreSQL interactive terminal.\n\n"
!                            "Type:  \\copyright for distribution terms\n"
                             "       \\h for help with SQL commands\n"
                             "       \\? for help with psql commands\n"
                "       \\g or terminate with semicolon to execute query\n"
!                            "       \\q to quit\n\n"),
!                    pset.progname, PG_VERSION);
  #ifdef USE_SSL
              printSSLInfo();
  #endif
--- 312,362 ----

          if (!QUIET() && !pset.notty)
          {
!             /*
!              *    Server value for 8.12 is 80102.
!              *    This code does not handle release numbers like
!              *    8.112.  (Is that 8.1, version 12, or 8.11, version 2?
!              */
!             int        client_ver_major_int = atoi(PG_VERSION) * 100 +
!                                        strchr(PG_VERSION, '.')[1] - '0';
!             int        client_ver_int = atoi(PG_VERSION) * 10000 +
!                                        (strchr(PG_VERSION, '.')[1] - '0') * 100 +
!                                        (isdigit(strchr(PG_VERSION, '.')[2]) ?
!                                        strchr(PG_VERSION, '.')[2] - '0' : '\0');
!
!             if (pset.sversion / 100 != client_ver_major_int)
!             {
!                 printf(_("WARNING:  You are connected to a server with major version %d.%d,\n"
!                          "but your %s client is major version %d.%d.  Informational backslash\n"
!                          "commands, like \\d, might not work properly.\n\n"),
!                          pset.sversion / 10000, (pset.sversion / 100) % 10,
!                          pset.progname, atoi(PG_VERSION), strchr(PG_VERSION, '.')[1] - '0');
!             }
!
!             if (pset.sversion != client_ver_int)
!             {
!                 char    server_ver_str[16];
!
!                 snprintf(server_ver_str, 16, "%d.%c%c", pset.sversion / 10000,
!                         (pset.sversion / 100) % 10 + '0',
!                         /* print last digit? */
!                         (pset.sversion % 10 != 0) ?
!                         pset.sversion % 10 + '0' : '\0');
!
!                 printf(_("Welcome to %s, the PostgreSQL interactive terminal.\n"),
!                          pset.progname);
!                 printf(_("psql version %s, server version %s\n\n"),
!                          PG_VERSION, server_ver_str);
!             }
!             else
!                 printf(_("Welcome to %s %s, the PostgreSQL interactive terminal.\n\n"),
!                      pset.progname, PG_VERSION);
!
!             printf(_("Type:  \\copyright for distribution terms\n"
                             "       \\h for help with SQL commands\n"
                             "       \\? for help with psql commands\n"
                "       \\g or terminate with semicolon to execute query\n"
!                            "       \\q to quit\n\n"));
  #ifdef USE_SSL
              printSSLInfo();
  #endif

pgsql-patches by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Note that spaces between QUOTE and DELIMITER are included
Next
From: Peter Eisentraut
Date:
Subject: Re: Updated french po files