Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1capMh-00085p-Fk for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Feb 2017 19:54:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1capMh-0001Le-2b for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Feb 2017 19:54:19 +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 1capMg-0001KO-9x for pgsql-hackers@postgresql.org; Mon, 06 Feb 2017 19:54:18 +0000 Received: from feynman.df7cb.de ([195.49.152.168]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1capMd-0006Zv-24 for pgsql-hackers@postgresql.org; Mon, 06 Feb 2017 19:54:17 +0000 Received: from msg.df7cb.de (unknown [IPv6:2a02:908:1470:60c0:76e5:bff:fef3:7e00]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by feynman.df7cb.de (Postfix) with ESMTPSA id 3vHJ855DVNz3Dyp for ; Mon, 6 Feb 2017 20:54:13 +0100 (CET) Date: Mon, 6 Feb 2017 20:54:13 +0100 From: Christoph Berg To: PostgreSQL Hackers Subject: Re: One-shot expanded output in psql using \gx Message-ID: <20170206195412.icfsozuj2fxlbbsa@msg.df7cb.de> Mail-Followup-To: Christoph Berg , PostgreSQL Hackers References: <20170127132737.6skslelaf4txs6iw@msg.credativ.de> <20170127150011.t6oynmocrgn4xd67@msg.credativ.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ycyt2fmlr7af7ko5" Content-Disposition: inline In-Reply-To: <20170127150011.t6oynmocrgn4xd67@msg.credativ.de> User-Agent: NeoMutt/20161126 (1.7.1) X-Pg-Spam-Score: -1.9 (-) 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 --ycyt2fmlr7af7ko5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The majority of voices here was in favor of using \gx, so here is another version of the same patch which implements that. Christoph --ycyt2fmlr7af7ko5 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="expanded-mode-gx.patch" diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml new file mode 100644 index ae58708..e0302ea *** a/doc/src/sgml/ref/psql-ref.sgml --- b/doc/src/sgml/ref/psql-ref.sgml *************** Tue Oct 26 21:40:57 CEST 1999 *** 1891,1896 **** --- 1891,1908 ---- + \gx [ filename ] + \gx [ |command ] + + + \gx is equivalent to \g, but + forces expanded output mode for this query. + + + + + + \gexec diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c new file mode 100644 index f17f610..6e140fe *** a/src/bin/psql/command.c --- b/src/bin/psql/command.c *************** exec_command(const char *cmd, *** 910,917 **** free(fname); } ! /* \g [filename] -- send query, optionally with output to file/pipe */ ! else if (strcmp(cmd, "g") == 0) { char *fname = psql_scan_slash_option(scan_state, OT_FILEPIPE, NULL, false); --- 910,920 ---- free(fname); } ! /* ! * \g [filename] -- send query, optionally with output to file/pipe ! * \gx [filename] -- same as \g, with expanded mode forced ! */ ! else if (strcmp(cmd, "g") == 0 || strcmp(cmd, "gx") == 0) { char *fname = psql_scan_slash_option(scan_state, OT_FILEPIPE, NULL, false); *************** exec_command(const char *cmd, *** 924,929 **** --- 927,934 ---- pset.gfname = pg_strdup(fname); } free(fname); + if (strcmp(cmd, "gx") == 0) + pset.g_expanded = true; status = PSQL_CMD_SEND; } diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c new file mode 100644 index 5349c39..4534bd9 *** a/src/bin/psql/common.c --- b/src/bin/psql/common.c *************** PrintQueryTuples(const PGresult *results *** 770,775 **** --- 770,779 ---- { printQueryOpt my_popt = pset.popt; + /* one-shot expanded output requested via \gx */ + if (pset.g_expanded) + my_popt.topt.expanded = true; + /* write output to \g argument, if any */ if (pset.gfname) { *************** sendquery_cleanup: *** 1410,1415 **** --- 1414,1422 ---- pset.gfname = NULL; } + /* reset \gx's expanded-mode flag */ + pset.g_expanded = false; + /* reset \gset trigger */ if (pset.gset_prefix) { diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c new file mode 100644 index 3e3cab4..2aece7e *** a/src/bin/psql/help.c --- b/src/bin/psql/help.c *************** slashUsage(unsigned short int pager) *** 174,179 **** --- 174,180 ---- fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n")); fprintf(output, _(" \\errverbose show most recent error message at maximum verbosity\n")); fprintf(output, _(" \\g [FILE] or ; execute query (and send results to file or |pipe)\n")); + fprintf(output, _(" \\gx [FILE] as \\g, but force expanded output\n")); fprintf(output, _(" \\gexec execute query, then execute each value in its result\n")); fprintf(output, _(" \\gset [PREFIX] execute query and store results in psql variables\n")); fprintf(output, _(" \\q quit psql\n")); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h new file mode 100644 index 195f5a1..70ff181 *** a/src/bin/psql/settings.h --- b/src/bin/psql/settings.h *************** typedef struct _psqlSettings *** 91,96 **** --- 91,97 ---- printQueryOpt popt; char *gfname; /* one-shot file output argument for \g */ + bool g_expanded; /* one-shot expanded output requested via \gx */ char *gset_prefix; /* one-shot prefix argument for \gset */ bool gexec_flag; /* one-shot flag to execute query's results */ bool crosstab_flag; /* one-shot request to crosstab results */ diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c new file mode 100644 index 6e759d0..0bd2ae3 *** a/src/bin/psql/tab-complete.c --- b/src/bin/psql/tab-complete.c *************** psql_completion(const char *text, int st *** 1338,1344 **** "\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\drds", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du", "\\dx", "\\dy", "\\e", "\\echo", "\\ef", "\\encoding", "\\errverbose", "\\ev", ! "\\f", "\\g", "\\gexec", "\\gset", "\\h", "\\help", "\\H", "\\i", "\\ir", "\\l", "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink", "\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r", "\\s", "\\set", "\\setenv", "\\sf", "\\sv", "\\t", "\\T", --- 1338,1344 ---- "\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\drds", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du", "\\dx", "\\dy", "\\e", "\\echo", "\\ef", "\\encoding", "\\errverbose", "\\ev", ! "\\f", "\\g", "\\gx", "\\gexec", "\\gset", "\\h", "\\help", "\\H", "\\i", "\\ir", "\\l", "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink", "\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r", "\\s", "\\set", "\\setenv", "\\sf", "\\sv", "\\t", "\\T", --ycyt2fmlr7af7ko5 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 --ycyt2fmlr7af7ko5--