PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
help.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include <sys/ioctl.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 37 of file help.c.

◆ HELPN

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

Definition at line 38 of file help.c.

◆ ON

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

Definition at line 39 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 48 of file help.c.

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

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