Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1douHh-0003As-Sd for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Sep 2017 16:31:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1douHg-0003K9-T3 for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Sep 2017 16:31:36 +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 1douHf-0003Ij-M5 for pgsql-hackers@postgresql.org; Mon, 04 Sep 2017 16:31:35 +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 1douHY-0008AB-78 for pgsql-hackers@postgresql.org; Mon, 04 Sep 2017 16:31:35 +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 v84GVJlB002948; Mon, 4 Sep 2017 12:31:19 -0400 From: Tom Lane To: Fabien COELHO cc: Robert Haas , Pavel Stehule , Corey Huinker , Daniel Verite , PostgreSQL Developers Subject: Re: Variable substitution in psql backtick expansion In-reply-to: References: <3926.1491159242@sss.pgh.pa.us> <13303.1503698976@sss.pgh.pa.us> <14596.1503701034@sss.pgh.pa.us> <20786.1503760136@sss.pgh.pa.us> <24850.1503766425@sss.pgh.pa.us> <4959.1503774468@sss.pgh.pa.us> Comments: In-reply-to Fabien COELHO message dated "Sun, 27 Aug 2017 08:13:15 +0200" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2863.1504542539.0@sss.pgh.pa.us> Date: Mon, 04 Sep 2017 12:31:19 -0400 Message-ID: <2947.1504542679@sss.pgh.pa.us> 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: <2863.1504542539.1@sss.pgh.pa.us> So I thought we were done bikeshedding the variable names for this feature, but as I was reviewing the patch with intent to commit, I noticed you hadn't updated helpVariables() to mention them. Possibly you missed this because it doesn't mention VERSION either, but that doesn't seem very defensible. I inserted text to describe all five variables --- but "SERVER_VERSION_NAME" is too long to fit in the available column space. In the attached updated patch, I moved all the descriptive text over one column, and really should have moved it over two columns; but adding even one space makes a couple of the lines longer than 80 columns when they were not before. Since we've blown past 80 columns on some of the other output, maybe that doesn't matter. Or maybe we should shorten this variable name so it doesn't force reformatting of all this text. Possible ideas include "DB_VERSION_NAME", "SERVER_VER_NAME", or "SERVER_VERSION_STR". (The last saves only one character, whereas we really need to save two if we're trying not to be wider than any other documented variable.) Thoughts? Attached updated patch changes helpVariables() as we'd need to do if not renaming, and does some minor doc/comment wordsmithing elsewhere. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="psql-version-num-7.patch"; charset="us-ascii" Content-ID: <2863.1504542539.2@sss.pgh.pa.us> Content-Description: psql-version-num-7.patch Content-Transfer-Encoding: quoted-printable diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index c592eda..a693fb9 100644 *** a/doc/src/sgml/ref/psql-ref.sgml --- b/doc/src/sgml/ref/psql-ref.sgml *************** bar *** 3688,3693 **** --- 3688,3717 ---- =20=20 + SERVER_VERSION_NAME + + + The server's version number as a string, for + example 9.6.2, 10.1, or 11beta1<= />. + This is set every time you connect to a database (including + program start-up), but can be changed or unset. + + + +=20 + + SERVER_VERSION_NUM + + + The server's version number in numeric form, for + example 90602 or 100001. + This is set every time you connect to a database (including + program start-up), but can be changed or unset. + + + +=20 + SINGLELINE *************** bar *** 3733,3742 **** =20=20 VERSION ! This variable is set at program start-up to ! reflect psql's version. It can be changed or uns= et. --- 3757,3771 ---- =20=20 VERSION + VERSION_NAME + VERSION_NUM ! These variables are set at program start-up to reflect ! psql's version, respectively as a verbose string, ! a short string (e.g., 9.6.2, 10.1, ! or 11beta1), and a number (e.g., 90602 ! or 100001). They can be changed or unset. diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 96f3a40..4283bf3 100644 *** a/src/bin/psql/command.c --- b/src/bin/psql/command.c *************** checkWin32Codepage(void) *** 3337,3342 **** --- 3337,3345 ---- void SyncVariables(void) { + char vbuf[32]; + const char *server_version; +=20 /* get stuff from connection */ pset.encoding =3D PQclientEncoding(pset.db); pset.popt.topt.encoding =3D pset.encoding; *************** SyncVariables(void) *** 3348,3353 **** --- 3351,3370 ---- SetVariable(pset.vars, "PORT", PQport(pset.db)); SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding)); =20=20 + /* this bit should match connection_warnings(): */ + /* Try to get full text form of version, 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, vbuf, sizeof(vbuf)); + server_version =3D vbuf; + } + SetVariable(pset.vars, "SERVER_VERSION_NAME", server_version); +=20 + snprintf(vbuf, sizeof(vbuf), "%d", pset.sversion); + SetVariable(pset.vars, "SERVER_VERSION_NUM", vbuf); +=20 /* send stuff to it, too */ PQsetErrorVerbosity(pset.db, pset.verbosity); PQsetErrorContextVisibility(pset.db, pset.show_context); *************** UnsyncVariables(void) *** 3366,3371 **** --- 3383,3390 ---- SetVariable(pset.vars, "HOST", NULL); SetVariable(pset.vars, "PORT", NULL); SetVariable(pset.vars, "ENCODING", NULL); + SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL); + SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL); } =20=20 =20=20 diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index b3dbb59..ee612b0 100644 *** a/src/bin/psql/help.c --- b/src/bin/psql/help.c *************** helpVariables(unsigned short int pager) *** 336,342 **** * Windows builds currently print one more line than non-Windows builds. * Using the larger number is fine. */ ! output =3D PageOutput(88, pager ? &(pset.popt.topt) : NULL); =20=20 fprintf(output, _("List of specially treated variables\n\n")); =20=20 --- 336,342 ---- * Windows builds currently print one more line than non-Windows builds. * Using the larger number is fine. */ ! output =3D PageOutput(93, pager ? &(pset.popt.topt) : NULL); =20=20 fprintf(output, _("List of specially treated variables\n\n")); =20=20 *************** helpVariables(unsigned short int pager) *** 344,378 **** fprintf(output, _("Usage:\n")); fprintf(output, _(" psql --set=3DNAME=3DVALUE\n or \\set NAME VALUE in= side psql\n\n")); =20=20 ! fprintf(output, _(" AUTOCOMMIT if set, successful SQL commands = are automatically committed\n")); ! fprintf(output, _(" COMP_KEYWORD_CASE determines the case used to comp= lete SQL key words\n" ! " [lower, upper, preserve-lower, preserve-uppe= r]\n")); ! fprintf(output, _(" DBNAME the currently connected database= name\n")); ! fprintf(output, _(" ECHO controls what input is written t= o standard output\n" ! " [all, errors, none, queries]\n")); ! fprintf(output, _(" ECHO_HIDDEN if set, display internal queries= executed by backslash commands;\n" ! " if set to \"noexec\", just show without exec= ution\n")); ! fprintf(output, _(" ENCODING current client character set enc= oding\n")); ! fprintf(output, _(" FETCH_COUNT the number of result rows to fet= ch and display at a time\n" ! " (default: 0=3Dunlimited)\n")); ! fprintf(output, _(" HISTCONTROL controls command history [ignore= space, ignoredups, ignoreboth]\n")); ! fprintf(output, _(" HISTFILE file name used to store the comm= and history\n")); ! fprintf(output, _(" HISTSIZE max number of commands to store = in the command history\n")); ! fprintf(output, _(" HOST the currently connected database= server host\n")); ! fprintf(output, _(" IGNOREEOF number of EOFs needed to termina= te an interactive session\n")); ! fprintf(output, _(" LASTOID value of the last affected OID\n= ")); ! fprintf(output, _(" ON_ERROR_ROLLBACK if set, an error doesn't stop a = transaction (uses implicit savepoints)\n")); ! fprintf(output, _(" ON_ERROR_STOP stop batch execution after error= \n")); ! fprintf(output, _(" PORT server port of the current conne= ction\n")); ! fprintf(output, _(" PROMPT1 specifies the standard psql prom= pt\n")); ! fprintf(output, _(" PROMPT2 specifies the prompt used when a= statement continues from a previous line\n")); ! fprintf(output, _(" PROMPT3 specifies the prompt used during= COPY ... FROM STDIN\n")); ! fprintf(output, _(" QUIET run quietly (same as -q option)\= n")); ! fprintf(output, _(" SHOW_CONTEXT controls display of message cont= ext fields [never, errors, always]\n")); ! fprintf(output, _(" SINGLELINE end of line terminates SQL comma= nd mode (same as -S option)\n")); ! fprintf(output, _(" SINGLESTEP single-step mode (same as -s opt= ion)\n")); ! fprintf(output, _(" USER the currently connected database= user\n")); ! fprintf(output, _(" VERBOSITY controls verbosity of error repo= rts [default, verbose, terse]\n")); =20=20 fprintf(output, _("\nDisplay settings:\n")); fprintf(output, _("Usage:\n")); --- 344,383 ---- fprintf(output, _("Usage:\n")); fprintf(output, _(" psql --set=3DNAME=3DVALUE\n or \\set NAME VALUE in= side psql\n\n")); =20=20 ! fprintf(output, _(" AUTOCOMMIT if set, successful SQL commands= are automatically committed\n")); ! fprintf(output, _(" COMP_KEYWORD_CASE determines the case used to com= plete SQL key words\n" ! " [lower, upper, preserve-lower, preserve-upp= er]\n")); ! fprintf(output, _(" DBNAME the currently connected databas= e name\n")); ! fprintf(output, _(" ECHO controls what input is written = to standard output\n" ! " [all, errors, none, queries]\n")); ! fprintf(output, _(" ECHO_HIDDEN if set, display internal querie= s executed by backslash commands;\n" ! " if set to \"noexec\", just show without exe= cution\n")); ! fprintf(output, _(" ENCODING current client character set en= coding\n")); ! fprintf(output, _(" FETCH_COUNT the number of result rows to fe= tch and display at a time\n" ! " (default: 0=3Dunlimited)\n")); ! fprintf(output, _(" HISTCONTROL controls command history [ignor= espace, ignoredups, ignoreboth]\n")); ! fprintf(output, _(" HISTFILE file name used to store the com= mand history\n")); ! fprintf(output, _(" HISTSIZE max number of commands to store= in the command history\n")); ! fprintf(output, _(" HOST the currently connected databas= e server host\n")); ! fprintf(output, _(" IGNOREEOF number of EOFs needed to termin= ate an interactive session\n")); ! fprintf(output, _(" LASTOID value of the last affected OID\= n")); ! fprintf(output, _(" ON_ERROR_ROLLBACK if set, an error doesn't stop a= transaction (uses implicit savepoints)\n")); ! fprintf(output, _(" ON_ERROR_STOP stop batch execution after erro= r\n")); ! fprintf(output, _(" PORT server port of the current conn= ection\n")); ! fprintf(output, _(" PROMPT1 specifies the standard psql pro= mpt\n")); ! fprintf(output, _(" PROMPT2 specifies the prompt used when = a statement continues from a previous line\n")); ! fprintf(output, _(" PROMPT3 specifies the prompt used durin= g COPY ... FROM STDIN\n")); ! fprintf(output, _(" QUIET run quietly (same as -q option)= \n")); ! fprintf(output, _(" SERVER_VERSION_NAME server's version (short string)= \n")); ! fprintf(output, _(" SERVER_VERSION_NUM server's version (numeric)\n")); ! fprintf(output, _(" SHOW_CONTEXT controls display of message con= text fields [never, errors, always]\n")); ! fprintf(output, _(" SINGLELINE end of line terminates SQL comm= and mode (same as -S option)\n")); ! fprintf(output, _(" SINGLESTEP single-step mode (same as -s op= tion)\n")); ! fprintf(output, _(" USER the currently connected databas= e user\n")); ! fprintf(output, _(" VERBOSITY controls verbosity of error rep= orts [default, verbose, terse]\n")); ! fprintf(output, _(" VERSION psql's version (verbose string)= \n")); ! fprintf(output, _(" VERSION_NAME psql's version (short string)\n= ")); ! fprintf(output, _(" VERSION_NUM psql's version (numeric)\n")); =20=20 fprintf(output, _("\nDisplay settings:\n")); fprintf(output, _("Usage:\n")); diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 7f76797..1e48f4a 100644 *** a/src/bin/psql/startup.c --- b/src/bin/psql/startup.c *************** main(int argc, char *argv[]) *** 160,166 **** --- 160,169 ---- =20=20 EstablishVariableSpace(); =20=20 + /* Create variables showing psql version number */ SetVariable(pset.vars, "VERSION", PG_VERSION_STR); + SetVariable(pset.vars, "VERSION_NAME", PG_VERSION); + SetVariable(pset.vars, "VERSION_NUM", CppAsString2(PG_VERSION_NUM)); =20=20 /* Default values for variables (that don't match the result of \unset) = */ SetVariableBool(pset.vars, "AUTOCOMMIT"); ------- =_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--