PostgreSQL Source Code  git master
help.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <sys/ioctl.h>
#include "common.h"
#include "common/logging.h"
#include "common/username.h"
#include "help.h"
#include "input.h"
#include "settings.h"
#include "sql_help.h"
Include dependency graph for help.c:

Go to the source code of this file.

Macros

#define HELP0(str)   appendPQExpBufferStr(&buf, _(str))
 
#define HELPN(str, ...)   appendPQExpBuffer(&buf, _(str), __VA_ARGS__)
 
#define ON(var)   ((var) ? _("on") : _("off"))
 
#define VALUE_OR_NULL(a)   ((a) ? (a) : "")
 

Functions

void usage (unsigned short int pager)
 
void slashUsage (unsigned short int pager)
 

Macro Definition Documentation

◆ HELP0

#define HELP0 (   str)    appendPQExpBufferStr(&buf, _(str))

Definition at line 40 of file help.c.

◆ HELPN

#define HELPN (   str,
  ... 
)    appendPQExpBuffer(&buf, _(str), __VA_ARGS__)

Definition at line 41 of file help.c.

◆ ON

#define ON (   var)    ((var) ? _("on") : _("off"))

Definition at line 42 of file help.c.

◆ VALUE_OR_NULL

#define VALUE_OR_NULL (   a)    ((a) ? (a) : "")

Function Documentation

◆ slashUsage()

◆ usage()

void usage ( unsigned short int  pager)

Definition at line 51 of file help.c.

52 {
54  int nlcount;
55  FILE *output;
56 
57  /*
58  * To avoid counting the output lines manually, build the output in "buf"
59  * and then count them.
60  */
62 
63  HELP0("psql is the PostgreSQL interactive terminal.\n\n");
64  HELP0("Usage:\n");
65  HELP0(" psql [OPTION]... [DBNAME [USERNAME]]\n\n");
66 
67  HELP0("General options:\n");
68  HELP0(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n");
69  HELP0(" -d, --dbname=DBNAME database name to connect to\n");
70  HELP0(" -f, --file=FILENAME execute commands from file, then exit\n");
71  HELP0(" -l, --list list available databases, then exit\n");
72  HELP0(" -v, --set=, --variable=NAME=VALUE\n"
73  " set psql variable NAME to VALUE\n"
74  " (e.g., -v ON_ERROR_STOP=1)\n");
75  HELP0(" -V, --version output version information, then exit\n");
76  HELP0(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n");
77  HELP0(" -1 (\"one\"), --single-transaction\n"
78  " execute as a single transaction (if non-interactive)\n");
79  HELP0(" -?, --help[=options] show this help, then exit\n");
80  HELP0(" --help=commands list backslash commands, then exit\n");
81  HELP0(" --help=variables list special variables, then exit\n");
82 
83  HELP0("\nInput and output options:\n");
84  HELP0(" -a, --echo-all echo all input from script\n");
85  HELP0(" -b, --echo-errors echo failed commands\n");
86  HELP0(" -e, --echo-queries echo commands sent to server\n");
87  HELP0(" -E, --echo-hidden display queries that internal commands generate\n");
88  HELP0(" -L, --log-file=FILENAME send session log to file\n");
89  HELP0(" -n, --no-readline disable enhanced command line editing (readline)\n");
90  HELP0(" -o, --output=FILENAME send query results to file (or |pipe)\n");
91  HELP0(" -q, --quiet run quietly (no messages, only query output)\n");
92  HELP0(" -s, --single-step single-step mode (confirm each query)\n");
93  HELP0(" -S, --single-line single-line mode (end of line terminates SQL command)\n");
94 
95  HELP0("\nOutput format options:\n");
96  HELP0(" -A, --no-align unaligned table output mode\n");
97  HELP0(" --csv CSV (Comma-Separated Values) table output mode\n");
98  HELPN(" -F, --field-separator=STRING\n"
99  " field separator for unaligned output (default: \"%s\")\n",
101  HELP0(" -H, --html HTML table output mode\n");
102  HELP0(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n");
103  HELP0(" -R, --record-separator=STRING\n"
104  " record separator for unaligned output (default: newline)\n");
105  HELP0(" -t, --tuples-only print rows only\n");
106  HELP0(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n");
107  HELP0(" -x, --expanded turn on expanded table output\n");
108  HELP0(" -z, --field-separator-zero\n"
109  " set field separator for unaligned output to zero byte\n");
110  HELP0(" -0, --record-separator-zero\n"
111  " set record separator for unaligned output to zero byte\n");
112 
113  HELP0("\nConnection options:\n");
114  HELP0(" -h, --host=HOSTNAME database server host or socket directory\n");
115  HELP0(" -p, --port=PORT database server port\n");
116  HELP0(" -U, --username=USERNAME database user name\n");
117  HELP0(" -w, --no-password never prompt for password\n");
118  HELP0(" -W, --password force password prompt (should happen automatically)\n");
119 
120  HELP0("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
121  "commands) from within psql, or consult the psql section in the PostgreSQL\n"
122  "documentation.\n\n");
123  HELPN("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
124  HELPN("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
125 
126  /* Now we can count the lines. */
127  nlcount = 0;
128  for (const char *ptr = buf.data; *ptr; ptr++)
129  {
130  if (*ptr == '\n')
131  nlcount++;
132  }
133 
134  /* And dump the output, with appropriate pagination. */
135  output = PageOutput(nlcount, pager ? &(pset.popt.topt) : NULL);
136 
137  fputs(buf.data, output);
138 
140 
142 }
void ClosePager(FILE *pagerpipe)
Definition: print.c:3141
FILE * PageOutput(int lines, const printTableOpt *topt)
Definition: print.c:3089
#define HELPN(str,...)
Definition: help.c:41
#define HELP0(str)
Definition: help.c:40
FILE * output
static char * buf
Definition: pg_test_fsync.c:73
void initPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:90
void termPQExpBuffer(PQExpBuffer str)
Definition: pqexpbuffer.c:129
#define DEFAULT_FIELD_SEP
Definition: settings.h:15
PsqlSettings pset
Definition: startup.c:32
printQueryOpt popt
Definition: settings.h:91
printTableOpt topt
Definition: print.h:185

References buf, ClosePager(), DEFAULT_FIELD_SEP, HELP0, HELPN, initPQExpBuffer(), output, PageOutput(), _psqlSettings::popt, pset, termPQExpBuffer(), and printQueryOpt::topt.