aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/command.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-08-16 15:58:30 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-08-16 15:58:46 -0400
commit32b99efd6a39ca06abe0514865da5f75e2e3f69b (patch)
tree2f417445fa2a09256e1d93229f0ab9fc33882766 /src/bin/psql/command.c
parent203bf7f4078451c2a75c21251882227cf67e1cd3 (diff)
downloadpostgresql-32b99efd6a39ca06abe0514865da5f75e2e3f69b.tar.gz
postgresql-32b99efd6a39ca06abe0514865da5f75e2e3f69b.zip
Fix assorted places in psql to print version numbers >= 10 in new style.
This is somewhat cosmetic, since as long as you know what you are looking at, "10.0" is a serviceable substitute for "10". But there is a potential for confusion between version numbers with minor numbers and those without --- we don't want people asking "why is psql saying 10.0 when my server is 10.2". Therefore, back-patch as far as practical, which turns out to be 9.3. I could have redone the patch to use fprintf(stderr) in place of psql_error(), but it seems more work than is warranted for branches that will be EOL or nearly so by the time v10 comes out. Although only psql seems to contain any code that needs this, I chose to put the support function into fe_utils, since it seems likely we'll need it in other client programs in future. (In 9.3-9.5, use dumputils.c, the predecessor of fe_utils/string_utils.c.) In HEAD, also fix the backend code that whines about loadable-library version mismatch. I don't see much need to back-patch that.
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r--src/bin/psql/command.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 9c0af4e8482..4aaf657cce8 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -635,8 +635,11 @@ exec_command(const char *cmd,
if (pset.sversion < 80400)
{
- psql_error("The server (version %d.%d) does not support editing function source.\n",
- pset.sversion / 10000, (pset.sversion / 100) % 100);
+ char sverbuf[32];
+
+ psql_error("The server (version %s) does not support editing function source.\n",
+ formatPGVersionNumber(pset.sversion, false,
+ sverbuf, sizeof(sverbuf)));
status = PSQL_CMD_ERROR;
}
else if (!query_buf)
@@ -731,8 +734,11 @@ exec_command(const char *cmd,
if (pset.sversion < 70400)
{
- psql_error("The server (version %d.%d) does not support editing view definitions.\n",
- pset.sversion / 10000, (pset.sversion / 100) % 100);
+ char sverbuf[32];
+
+ psql_error("The server (version %s) does not support editing view definitions.\n",
+ formatPGVersionNumber(pset.sversion, false,
+ sverbuf, sizeof(sverbuf)));
status = PSQL_CMD_ERROR;
}
else if (!query_buf)
@@ -1362,8 +1368,11 @@ exec_command(const char *cmd,
OT_WHOLE_LINE, NULL, true);
if (pset.sversion < 80400)
{
- psql_error("The server (version %d.%d) does not support showing function source.\n",
- pset.sversion / 10000, (pset.sversion / 100) % 100);
+ char sverbuf[32];
+
+ psql_error("The server (version %s) does not support showing function source.\n",
+ formatPGVersionNumber(pset.sversion, false,
+ sverbuf, sizeof(sverbuf)));
status = PSQL_CMD_ERROR;
}
else if (!func)
@@ -1441,8 +1450,11 @@ exec_command(const char *cmd,
OT_WHOLE_LINE, NULL, true);
if (pset.sversion < 70400)
{
- psql_error("The server (version %d.%d) does not support showing view definitions.\n",
- pset.sversion / 10000, (pset.sversion / 100) % 100);
+ char sverbuf[32];
+
+ psql_error("The server (version %s) does not support showing view definitions.\n",
+ formatPGVersionNumber(pset.sversion, false,
+ sverbuf, sizeof(sverbuf)));
status = PSQL_CMD_ERROR;
}
else if (!view)
@@ -2014,22 +2026,21 @@ connection_warnings(bool in_startup)
if (!pset.quiet && !pset.notty)
{
int client_ver = PG_VERSION_NUM;
+ char cverbuf[32];
+ char sverbuf[32];
if (pset.sversion != client_ver)
{
const char *server_version;
- char server_ver_str[16];
/* Try to get full text form, might include "devel" etc */
server_version = PQparameterStatus(pset.db, "server_version");
+ /* Otherwise fall back on pset.sversion */
if (!server_version)
{
- snprintf(server_ver_str, sizeof(server_ver_str),
- "%d.%d.%d",
- pset.sversion / 10000,
- (pset.sversion / 100) % 100,
- pset.sversion % 100);
- server_version = server_ver_str;
+ formatPGVersionNumber(pset.sversion, true,
+ sverbuf, sizeof(sverbuf));
+ server_version = sverbuf;
}
printf(_("%s (%s, server %s)\n"),
@@ -2040,10 +2051,13 @@ connection_warnings(bool in_startup)
printf("%s (%s)\n", pset.progname, PG_VERSION);
if (pset.sversion / 100 > client_ver / 100)
- printf(_("WARNING: %s major version %d.%d, server major version %d.%d.\n"
+ printf(_("WARNING: %s major version %s, server major version %s.\n"
" Some psql features might not work.\n"),
- pset.progname, client_ver / 10000, (client_ver / 100) % 100,
- pset.sversion / 10000, (pset.sversion / 100) % 100);
+ pset.progname,
+ formatPGVersionNumber(client_ver, false,
+ cverbuf, sizeof(cverbuf)),
+ formatPGVersionNumber(pset.sversion, false,
+ sverbuf, sizeof(sverbuf)));
#ifdef WIN32
checkWin32Codepage();