mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Create a psql command \gset to store query results into psql variables.
This eases manipulation of query results in psql scripts. Pavel Stehule, reviewed by Piyush Newe, Shigeru Hanada, and Tom Lane
This commit is contained in:
@ -731,7 +731,7 @@ exec_command(const char *cmd,
|
||||
free(fname);
|
||||
}
|
||||
|
||||
/* \g [filename] means send query, optionally with output to file/pipe */
|
||||
/* \g [filename] -- send query, optionally with output to file/pipe */
|
||||
else if (strcmp(cmd, "g") == 0)
|
||||
{
|
||||
char *fname = psql_scan_slash_option(scan_state,
|
||||
@ -748,6 +748,22 @@ exec_command(const char *cmd,
|
||||
status = PSQL_CMD_SEND;
|
||||
}
|
||||
|
||||
/* \gset [prefix] -- send query and store result into variables */
|
||||
else if (strcmp(cmd, "gset") == 0)
|
||||
{
|
||||
char *prefix = psql_scan_slash_option(scan_state,
|
||||
OT_NORMAL, NULL, false);
|
||||
|
||||
if (prefix)
|
||||
pset.gset_prefix = prefix;
|
||||
else
|
||||
{
|
||||
/* we must set a non-NULL prefix to trigger storing */
|
||||
pset.gset_prefix = pg_strdup("");
|
||||
}
|
||||
status = PSQL_CMD_SEND;
|
||||
}
|
||||
|
||||
/* help */
|
||||
else if (strcmp(cmd, "h") == 0 || strcmp(cmd, "help") == 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user