aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/command.c
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2017-03-07 09:31:52 -0500
committerStephen Frost <sfrost@snowman.net>2017-03-07 09:31:52 -0500
commitb2678efd43f17db7dfa04e0ca076ea01275cd9bc (patch)
tree286017423ffd724b3759be1141dc67df45484eae /src/bin/psql/command.c
parent9a83d56b38c870ce47b7651385ff2add583bf136 (diff)
downloadpostgresql-b2678efd43f17db7dfa04e0ca076ea01275cd9bc.tar.gz
postgresql-b2678efd43f17db7dfa04e0ca076ea01275cd9bc.zip
psql: Add \gx command
It can often be useful to use expanded mode output (\x) for just a single query. Introduce a \gx which acts exactly like \g except that it will force expanded output mode for that one \gx call. This is simpler than having to use \x as a toggle and also means that the user doesn't have to worry about the current state of the expanded variable, or resetting it later, to ensure a given query is always returned in expanded mode. Primairly Christoph's patch, though I did tweak the documentation and help text a bit, and re-indented the tab completion section. Author: Christoph Berg Reviewed By: Daniel Verite Discussion: https://postgr.es/m/20170127132737.6skslelaf4txs6iw%40msg.credativ.de
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r--src/bin/psql/command.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index a52adc8186f..07efc27a697 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -906,8 +906,11 @@ exec_command(const char *cmd,
free(fname);
}
- /* \g [filename] -- send query, optionally with output to file/pipe */
- else if (strcmp(cmd, "g") == 0)
+ /*
+ * \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);
@@ -920,6 +923,8 @@ exec_command(const char *cmd,
pset.gfname = pg_strdup(fname);
}
free(fname);
+ if (strcmp(cmd, "gx") == 0)
+ pset.g_expanded = true;
status = PSQL_CMD_SEND;
}