PostgreSQL/src/bin/psql/command.h
Tom Lane b63c293bcb Allow psql's \g and \gx commands to transiently change \pset options.
We invented \gx to allow the "\pset expanded" flag to be forced on
for the duration of one command output, but that turns out to not
be nearly enough to satisfy the demand for variant output formats.
Hence, make it possible to change any pset option(s) for the duration
of a single command output, by writing "option=value ..." inside
parentheses, for example
	\g (format=csv csv_fieldsep='\t') somefile

\gx can now be understood as a shorthand for including expanded=on
inside the parentheses.

Patch by me, expanding on a proposal by Pavel Stehule

Discussion: https://postgr.es/m/CAFj8pRBx9OnBPRJVtfA5ycUpySge-XootAXAsv_4rrkHxJ8eRg@mail.gmail.com
2020-04-07 17:46:29 -04:00

50 lines
1.3 KiB
C

/*
* psql - the PostgreSQL interactive terminal
*
* Copyright (c) 2000-2020, PostgreSQL Global Development Group
*
* src/bin/psql/command.h
*/
#ifndef COMMAND_H
#define COMMAND_H
#include "fe_utils/conditional.h"
#include "fe_utils/print.h"
#include "fe_utils/psqlscan.h"
typedef enum _backslashResult
{
PSQL_CMD_UNKNOWN = 0, /* not done parsing yet (internal only) */
PSQL_CMD_SEND, /* query complete; send off */
PSQL_CMD_SKIP_LINE, /* keep building query */
PSQL_CMD_TERMINATE, /* quit program */
PSQL_CMD_NEWEDIT, /* query buffer was changed (e.g., via \e) */
PSQL_CMD_ERROR /* the execution of the backslash command
* resulted in an error */
} backslashResult;
extern backslashResult HandleSlashCmds(PsqlScanState scan_state,
ConditionalStack cstack,
PQExpBuffer query_buf,
PQExpBuffer previous_buf);
extern int process_file(char *filename, bool use_relative_path);
extern bool do_pset(const char *param,
const char *value,
printQueryOpt *popt,
bool quiet);
extern printQueryOpt *savePsetInfo(const printQueryOpt *popt);
extern void restorePsetInfo(printQueryOpt *popt, printQueryOpt *save);
extern void connection_warnings(bool in_startup);
extern void SyncVariables(void);
extern void UnsyncVariables(void);
#endif /* COMMAND_H */