Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bZPVK-0002PO-8z for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Aug 2016 21:33:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bZPVJ-0005H5-4w for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Aug 2016 21:33:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bZPTu-0003lZ-Do for pgsql-hackers@postgreSQL.org; Mon, 15 Aug 2016 21:31:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bZPTm-0003vk-Qy for pgsql-hackers@postgreSQL.org; Mon, 15 Aug 2016 21:31:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u7FLVR5W027648; Mon, 15 Aug 2016 17:31:27 -0400 From: Tom Lane To: Peter Eisentraut cc: pgsql-hackers@postgreSQL.org Subject: Re: New version numbering practices In-reply-to: <19303.1471283612@sss.pgh.pa.us> References: <7684.1470066581@sss.pgh.pa.us> <802ec140-635d-ad86-5fdf-d3af0e260c22@2ndquadrant.com> <19303.1471283612@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 15 Aug 2016 13:53:32 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <27615.1471296665.0@sss.pgh.pa.us> Date: Mon, 15 Aug 2016 17:31:27 -0400 Message-ID: <27647.1471296687@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27615.1471296665.1@sss.pgh.pa.us> I wrote: > I've pushed this with minor additional twiddling. We can work on the > "UI issues" you mentioned at leisure. One that I noted is that psql's > version-mismatch-warning messages aren't two-part-version aware, and > will print "10.0" where they should say "10". Probably that fix should > get back-patched, so that older psql branches will do the right thing > if possible. Attached is a WIP patch for that. I've only fixed psql/command.c so far, but I put the support logic into fe_utils since we're going to need it in some other places too (pg_dump at least). Any objections to this general approach? regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="client-version-number-printing-0.1.patch"; charset="us-ascii" Content-ID: <27615.1471296665.2@sss.pgh.pa.us> Content-Description: client-version-number-printing-0.1.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 9c0af4e..4aaf657 100644 *** a/src/bin/psql/command.c --- b/src/bin/psql/command.c *************** exec_command(const char *cmd, *** 635,642 **** =20=20 if (pset.sversion < 80400) { ! psql_error("The server (version %d.%d) does not support editing functi= on source.\n", ! pset.sversion / 10000, (pset.sversion / 100) % 100); status =3D PSQL_CMD_ERROR; } else if (!query_buf) --- 635,645 ---- =20=20 if (pset.sversion < 80400) { ! char sverbuf[32]; !=20 ! psql_error("The server (version %s) does not support editing function = source.\n", ! formatPGVersionNumber(pset.sversion, false, ! sverbuf, sizeof(sverbuf))); status =3D PSQL_CMD_ERROR; } else if (!query_buf) *************** exec_command(const char *cmd, *** 731,738 **** =20=20 if (pset.sversion < 70400) { ! psql_error("The server (version %d.%d) does not support editing view d= efinitions.\n", ! pset.sversion / 10000, (pset.sversion / 100) % 100); status =3D PSQL_CMD_ERROR; } else if (!query_buf) --- 734,744 ---- =20=20 if (pset.sversion < 70400) { ! char sverbuf[32]; !=20 ! psql_error("The server (version %s) does not support editing view defi= nitions.\n", ! formatPGVersionNumber(pset.sversion, false, ! sverbuf, sizeof(sverbuf))); status =3D PSQL_CMD_ERROR; } else if (!query_buf) *************** exec_command(const char *cmd, *** 1362,1369 **** OT_WHOLE_LINE, NULL, true); if (pset.sversion < 80400) { ! psql_error("The server (version %d.%d) does not support showing functi= on source.\n", ! pset.sversion / 10000, (pset.sversion / 100) % 100); status =3D PSQL_CMD_ERROR; } else if (!func) --- 1368,1378 ---- OT_WHOLE_LINE, NULL, true); if (pset.sversion < 80400) { ! char sverbuf[32]; !=20 ! psql_error("The server (version %s) does not support showing function = source.\n", ! formatPGVersionNumber(pset.sversion, false, ! sverbuf, sizeof(sverbuf))); status =3D PSQL_CMD_ERROR; } else if (!func) *************** exec_command(const char *cmd, *** 1441,1448 **** OT_WHOLE_LINE, NULL, true); if (pset.sversion < 70400) { ! psql_error("The server (version %d.%d) does not support showing view d= efinitions.\n", ! pset.sversion / 10000, (pset.sversion / 100) % 100); status =3D PSQL_CMD_ERROR; } else if (!view) --- 1450,1460 ---- OT_WHOLE_LINE, NULL, true); if (pset.sversion < 70400) { ! char sverbuf[32]; !=20 ! psql_error("The server (version %s) does not support showing view defi= nitions.\n", ! formatPGVersionNumber(pset.sversion, false, ! sverbuf, sizeof(sverbuf))); status =3D PSQL_CMD_ERROR; } else if (!view) *************** connection_warnings(bool in_startup) *** 2014,2035 **** if (!pset.quiet && !pset.notty) { int client_ver =3D PG_VERSION_NUM; =20=20 if (pset.sversion !=3D client_ver) { const char *server_version; - char server_ver_str[16]; =20=20 /* Try to get full text form, might include "devel" etc */ server_version =3D PQparameterStatus(pset.db, "server_version"); 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 =3D server_ver_str; } =20=20 printf(_("%s (%s, server %s)\n"), --- 2026,2046 ---- if (!pset.quiet && !pset.notty) { int client_ver =3D PG_VERSION_NUM; + char cverbuf[32]; + char sverbuf[32]; =20=20 if (pset.sversion !=3D client_ver) { const char *server_version; =20=20 /* Try to get full text form, might include "devel" etc */ server_version =3D PQparameterStatus(pset.db, "server_version"); + /* Otherwise fall back on pset.sversion */ if (!server_version) { ! formatPGVersionNumber(pset.sversion, true, ! sverbuf, sizeof(sverbuf)); ! server_version =3D sverbuf; } =20=20 printf(_("%s (%s, server %s)\n"), *************** connection_warnings(bool in_startup) *** 2040,2049 **** printf("%s (%s)\n", pset.progname, PG_VERSION); =20=20 if (pset.sversion / 100 > client_ver / 100) ! printf(_("WARNING: %s major version %d.%d, server major version %d.%d.= \n" " Some psql features might not work.\n"), ! pset.progname, client_ver / 10000, (client_ver / 100) % 100, ! pset.sversion / 10000, (pset.sversion / 100) % 100); =20=20 #ifdef WIN32 checkWin32Codepage(); --- 2051,2063 ---- printf("%s (%s)\n", pset.progname, PG_VERSION); =20=20 if (pset.sversion / 100 > client_ver / 100) ! printf(_("WARNING: %s major version %s, server major version %s.\n" " Some psql features might not work.\n"), ! pset.progname, ! formatPGVersionNumber(client_ver, false, ! cverbuf, sizeof(cverbuf)), ! formatPGVersionNumber(pset.sversion, false, ! sverbuf, sizeof(sverbuf))); =20=20 #ifdef WIN32 checkWin32Codepage(); diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c index f986dbc..2c566b1 100644 *** a/src/fe_utils/string_utils.c --- b/src/fe_utils/string_utils.c *************** fmtQualifiedId(int remoteVersion, const=20 *** 169,174 **** --- 169,212 ---- =20=20 =20=20 /* + * Format a Postgres version number (in the PG_VERSION_NUM integer format + * returned by PQserverVersion()) as a string. This exists mainly to + * encapsulate knowledge about two-part vs. three-part version numbers. + * + * For re-entrancy, caller must supply the buffer the string is put in. + * Recommended size of the buffer is 32 bytes. + * + * Returns address of 'buf', as a notational convenience. + */ + char * + formatPGVersionNumber(int version_number, bool include_minor, + char *buf, size_t buflen) + { + if (version_number >=3D 100000) + { + /* New two-part style */ + if (include_minor) + snprintf(buf, buflen, "%d.%d", version_number / 10000, + version_number % 10000); + else + snprintf(buf, buflen, "%d", version_number / 10000); + } + else + { + /* Old three-part style */ + if (include_minor) + snprintf(buf, buflen, "%d.%d.%d", version_number / 10000, + (version_number / 100) % 100, + version_number % 100); + else + snprintf(buf, buflen, "%d.%d", version_number / 10000, + (version_number / 100) % 100); + } + return buf; + } +=20 +=20 + /* * Convert a string value to an SQL string literal and append it to * the given buffer. We assume the specified client_encoding and * standard_conforming_strings settings. diff --git a/src/include/fe_utils/string_utils.h b/src/include/fe_utils/str= ing_utils.h index 7bbed36..452ffc0 100644 *** a/src/include/fe_utils/string_utils.h --- b/src/include/fe_utils/string_utils.h *************** extern const char *fmtId(const char *ide *** 30,35 **** --- 30,38 ---- extern const char *fmtQualifiedId(int remoteVersion, const char *schema, const char *id); =20=20 + extern char *formatPGVersionNumber(int version_number, bool include_minor, + char *buf, size_t buflen); +=20 extern void appendStringLiteral(PQExpBuffer buf, const char *str, int encoding, bool std_strings); extern void appendStringLiteralConn(PQExpBuffer buf, const char *str, ------- =_aaaaaaaaaa0 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers ------- =_aaaaaaaaaa0--