Line data Source code
1 : /*
2 : * psql - the PostgreSQL interactive terminal
3 : *
4 : * Copyright (c) 2000-2017, PostgreSQL Global Development Group
5 : *
6 : * src/bin/psql/help.c
7 : */
8 : #include "postgres_fe.h"
9 :
10 : #ifndef WIN32
11 : #include <unistd.h> /* for geteuid() */
12 : #else
13 : #include <win32.h>
14 : #endif
15 :
16 : #ifndef WIN32
17 : #include <sys/ioctl.h> /* for ioctl() */
18 : #endif
19 :
20 : #ifdef HAVE_TERMIOS_H
21 : #include <termios.h>
22 : #endif
23 :
24 : #include "common.h"
25 : #include "common/username.h"
26 : #include "help.h"
27 : #include "input.h"
28 : #include "settings.h"
29 : #include "sql_help.h"
30 :
31 :
32 : /*
33 : * PLEASE:
34 : * If you change something in this file, also make the same changes
35 : * in the DocBook documentation, file ref/psql-ref.sgml. If you don't
36 : * know how to do it, please find someone who can help you.
37 : */
38 :
39 :
40 : /*
41 : * usage
42 : *
43 : * print out command line arguments
44 : */
45 : #define ON(var) (var ? _("on") : _("off"))
46 :
47 : void
48 0 : usage(unsigned short int pager)
49 : {
50 : const char *env;
51 : const char *user;
52 : char *errstr;
53 : FILE *output;
54 :
55 : /* Find default user, in case we need it. */
56 0 : user = getenv("PGUSER");
57 0 : if (!user)
58 : {
59 0 : user = get_user_name(&errstr);
60 0 : if (!user)
61 : {
62 0 : psql_error("%s\n", errstr);
63 0 : exit(EXIT_FAILURE);
64 : }
65 : }
66 :
67 : /*
68 : * Keep this line count in sync with the number of lines printed below!
69 : * Use "psql --help=options | wc" to count correctly.
70 : */
71 0 : output = PageOutput(61, pager ? &(pset.popt.topt) : NULL);
72 :
73 0 : fprintf(output, _("psql is the PostgreSQL interactive terminal.\n\n"));
74 0 : fprintf(output, _("Usage:\n"));
75 0 : fprintf(output, _(" psql [OPTION]... [DBNAME [USERNAME]]\n\n"));
76 :
77 0 : fprintf(output, _("General options:\n"));
78 : /* Display default database */
79 0 : env = getenv("PGDATABASE");
80 0 : if (!env)
81 0 : env = user;
82 0 : fprintf(output, _(" -c, --command=COMMAND run only single command (SQL or internal) and exit\n"));
83 0 : fprintf(output, _(" -d, --dbname=DBNAME database name to connect to (default: \"%s\")\n"), env);
84 0 : fprintf(output, _(" -f, --file=FILENAME execute commands from file, then exit\n"));
85 0 : fprintf(output, _(" -l, --list list available databases, then exit\n"));
86 0 : fprintf(output, _(" -v, --set=, --variable=NAME=VALUE\n"
87 : " set psql variable NAME to VALUE\n"
88 : " (e.g., -v ON_ERROR_STOP=1)\n"));
89 0 : fprintf(output, _(" -V, --version output version information, then exit\n"));
90 0 : fprintf(output, _(" -X, --no-psqlrc do not read startup file (~/.psqlrc)\n"));
91 0 : fprintf(output, _(" -1 (\"one\"), --single-transaction\n"
92 : " execute as a single transaction (if non-interactive)\n"));
93 0 : fprintf(output, _(" -?, --help[=options] show this help, then exit\n"));
94 0 : fprintf(output, _(" --help=commands list backslash commands, then exit\n"));
95 0 : fprintf(output, _(" --help=variables list special variables, then exit\n"));
96 :
97 0 : fprintf(output, _("\nInput and output options:\n"));
98 0 : fprintf(output, _(" -a, --echo-all echo all input from script\n"));
99 0 : fprintf(output, _(" -b, --echo-errors echo failed commands\n"));
100 0 : fprintf(output, _(" -e, --echo-queries echo commands sent to server\n"));
101 0 : fprintf(output, _(" -E, --echo-hidden display queries that internal commands generate\n"));
102 0 : fprintf(output, _(" -L, --log-file=FILENAME send session log to file\n"));
103 0 : fprintf(output, _(" -n, --no-readline disable enhanced command line editing (readline)\n"));
104 0 : fprintf(output, _(" -o, --output=FILENAME send query results to file (or |pipe)\n"));
105 0 : fprintf(output, _(" -q, --quiet run quietly (no messages, only query output)\n"));
106 0 : fprintf(output, _(" -s, --single-step single-step mode (confirm each query)\n"));
107 0 : fprintf(output, _(" -S, --single-line single-line mode (end of line terminates SQL command)\n"));
108 :
109 0 : fprintf(output, _("\nOutput format options:\n"));
110 0 : fprintf(output, _(" -A, --no-align unaligned table output mode\n"));
111 0 : fprintf(output, _(" -F, --field-separator=STRING\n"
112 : " field separator for unaligned output (default: \"%s\")\n"),
113 : DEFAULT_FIELD_SEP);
114 0 : fprintf(output, _(" -H, --html HTML table output mode\n"));
115 0 : fprintf(output, _(" -P, --pset=VAR[=ARG] set printing option VAR to ARG (see \\pset command)\n"));
116 0 : fprintf(output, _(" -R, --record-separator=STRING\n"
117 : " record separator for unaligned output (default: newline)\n"));
118 0 : fprintf(output, _(" -t, --tuples-only print rows only\n"));
119 0 : fprintf(output, _(" -T, --table-attr=TEXT set HTML table tag attributes (e.g., width, border)\n"));
120 0 : fprintf(output, _(" -x, --expanded turn on expanded table output\n"));
121 0 : fprintf(output, _(" -z, --field-separator-zero\n"
122 : " set field separator for unaligned output to zero byte\n"));
123 0 : fprintf(output, _(" -0, --record-separator-zero\n"
124 : " set record separator for unaligned output to zero byte\n"));
125 :
126 0 : fprintf(output, _("\nConnection options:\n"));
127 : /* Display default host */
128 0 : env = getenv("PGHOST");
129 0 : fprintf(output, _(" -h, --host=HOSTNAME database server host or socket directory (default: \"%s\")\n"),
130 : env ? env : _("local socket"));
131 : /* Display default port */
132 0 : env = getenv("PGPORT");
133 0 : fprintf(output, _(" -p, --port=PORT database server port (default: \"%s\")\n"),
134 : env ? env : DEF_PGPORT_STR);
135 : /* Display default user */
136 0 : env = getenv("PGUSER");
137 0 : if (!env)
138 0 : env = user;
139 0 : fprintf(output, _(" -U, --username=USERNAME database user name (default: \"%s\")\n"), env);
140 0 : fprintf(output, _(" -w, --no-password never prompt for password\n"));
141 0 : fprintf(output, _(" -W, --password force password prompt (should happen automatically)\n"));
142 :
143 0 : fprintf(output, _("\nFor more information, type \"\\?\" (for internal commands) or \"\\help\" (for SQL\n"
144 : "commands) from within psql, or consult the psql section in the PostgreSQL\n"
145 : "documentation.\n\n"));
146 0 : fprintf(output, _("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
147 :
148 0 : ClosePager(output);
149 0 : }
150 :
151 :
152 : /*
153 : * slashUsage
154 : *
155 : * print out help for the backslash commands
156 : */
157 : void
158 0 : slashUsage(unsigned short int pager)
159 : {
160 : FILE *output;
161 : char *currdb;
162 :
163 0 : currdb = PQdb(pset.db);
164 :
165 : /*
166 : * Keep this line count in sync with the number of lines printed below!
167 : * Use "psql --help=commands | wc" to count correctly. It's okay to count
168 : * the USE_READLINE line even in builds without that.
169 : */
170 0 : output = PageOutput(122, pager ? &(pset.popt.topt) : NULL);
171 :
172 0 : fprintf(output, _("General\n"));
173 0 : fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n"));
174 0 : fprintf(output, _(" \\crosstabview [COLUMNS] execute query and display results in crosstab\n"));
175 0 : fprintf(output, _(" \\errverbose show most recent error message at maximum verbosity\n"));
176 0 : fprintf(output, _(" \\g [FILE] or ; execute query (and send results to file or |pipe)\n"));
177 0 : fprintf(output, _(" \\gexec execute query, then execute each value in its result\n"));
178 0 : fprintf(output, _(" \\gset [PREFIX] execute query and store results in psql variables\n"));
179 0 : fprintf(output, _(" \\gx [FILE] as \\g, but forces expanded output mode\n"));
180 0 : fprintf(output, _(" \\q quit psql\n"));
181 0 : fprintf(output, _(" \\watch [SEC] execute query every SEC seconds\n"));
182 0 : fprintf(output, "\n");
183 :
184 0 : fprintf(output, _("Help\n"));
185 :
186 0 : fprintf(output, _(" \\? [commands] show help on backslash commands\n"));
187 0 : fprintf(output, _(" \\? options show help on psql command-line options\n"));
188 0 : fprintf(output, _(" \\? variables show help on special variables\n"));
189 0 : fprintf(output, _(" \\h [NAME] help on syntax of SQL commands, * for all commands\n"));
190 0 : fprintf(output, "\n");
191 :
192 0 : fprintf(output, _("Query Buffer\n"));
193 0 : fprintf(output, _(" \\e [FILE] [LINE] edit the query buffer (or file) with external editor\n"));
194 0 : fprintf(output, _(" \\ef [FUNCNAME [LINE]] edit function definition with external editor\n"));
195 0 : fprintf(output, _(" \\ev [VIEWNAME [LINE]] edit view definition with external editor\n"));
196 0 : fprintf(output, _(" \\p show the contents of the query buffer\n"));
197 0 : fprintf(output, _(" \\r reset (clear) the query buffer\n"));
198 : #ifdef USE_READLINE
199 0 : fprintf(output, _(" \\s [FILE] display history or save it to file\n"));
200 : #endif
201 0 : fprintf(output, _(" \\w FILE write query buffer to file\n"));
202 0 : fprintf(output, "\n");
203 :
204 0 : fprintf(output, _("Input/Output\n"));
205 0 : fprintf(output, _(" \\copy ... perform SQL COPY with data stream to the client host\n"));
206 0 : fprintf(output, _(" \\echo [STRING] write string to standard output\n"));
207 0 : fprintf(output, _(" \\i FILE execute commands from file\n"));
208 0 : fprintf(output, _(" \\ir FILE as \\i, but relative to location of current script\n"));
209 0 : fprintf(output, _(" \\o [FILE] send all query results to file or |pipe\n"));
210 0 : fprintf(output, _(" \\qecho [STRING] write string to query output stream (see \\o)\n"));
211 0 : fprintf(output, "\n");
212 :
213 0 : fprintf(output, _("Conditional\n"));
214 0 : fprintf(output, _(" \\if EXPR begin conditional block\n"));
215 0 : fprintf(output, _(" \\elif EXPR alternative within current conditional block\n"));
216 0 : fprintf(output, _(" \\else final alternative within current conditional block\n"));
217 0 : fprintf(output, _(" \\endif end conditional block\n"));
218 0 : fprintf(output, "\n");
219 :
220 0 : fprintf(output, _("Informational\n"));
221 0 : fprintf(output, _(" (options: S = show system objects, + = additional detail)\n"));
222 0 : fprintf(output, _(" \\d[S+] list tables, views, and sequences\n"));
223 0 : fprintf(output, _(" \\d[S+] NAME describe table, view, sequence, or index\n"));
224 0 : fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n"));
225 0 : fprintf(output, _(" \\dA[+] [PATTERN] list access methods\n"));
226 0 : fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
227 0 : fprintf(output, _(" \\dc[S+] [PATTERN] list conversions\n"));
228 0 : fprintf(output, _(" \\dC[+] [PATTERN] list casts\n"));
229 0 : fprintf(output, _(" \\dd[S] [PATTERN] show object descriptions not displayed elsewhere\n"));
230 0 : fprintf(output, _(" \\dD[S+] [PATTERN] list domains\n"));
231 0 : fprintf(output, _(" \\ddp [PATTERN] list default privileges\n"));
232 0 : fprintf(output, _(" \\dE[S+] [PATTERN] list foreign tables\n"));
233 0 : fprintf(output, _(" \\det[+] [PATTERN] list foreign tables\n"));
234 0 : fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n"));
235 0 : fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n"));
236 0 : fprintf(output, _(" \\dew[+] [PATTERN] list foreign-data wrappers\n"));
237 0 : fprintf(output, _(" \\df[antw][S+] [PATRN] list [only agg/normal/trigger/window] functions\n"));
238 0 : fprintf(output, _(" \\dF[+] [PATTERN] list text search configurations\n"));
239 0 : fprintf(output, _(" \\dFd[+] [PATTERN] list text search dictionaries\n"));
240 0 : fprintf(output, _(" \\dFp[+] [PATTERN] list text search parsers\n"));
241 0 : fprintf(output, _(" \\dFt[+] [PATTERN] list text search templates\n"));
242 0 : fprintf(output, _(" \\dg[S+] [PATTERN] list roles\n"));
243 0 : fprintf(output, _(" \\di[S+] [PATTERN] list indexes\n"));
244 0 : fprintf(output, _(" \\dl list large objects, same as \\lo_list\n"));
245 0 : fprintf(output, _(" \\dL[S+] [PATTERN] list procedural languages\n"));
246 0 : fprintf(output, _(" \\dm[S+] [PATTERN] list materialized views\n"));
247 0 : fprintf(output, _(" \\dn[S+] [PATTERN] list schemas\n"));
248 0 : fprintf(output, _(" \\do[S] [PATTERN] list operators\n"));
249 0 : fprintf(output, _(" \\dO[S+] [PATTERN] list collations\n"));
250 0 : fprintf(output, _(" \\dp [PATTERN] list table, view, and sequence access privileges\n"));
251 0 : fprintf(output, _(" \\drds [PATRN1 [PATRN2]] list per-database role settings\n"));
252 0 : fprintf(output, _(" \\dRp[+] [PATTERN] list replication publications\n"));
253 0 : fprintf(output, _(" \\dRs[+] [PATTERN] list replication subscriptions\n"));
254 0 : fprintf(output, _(" \\ds[S+] [PATTERN] list sequences\n"));
255 0 : fprintf(output, _(" \\dt[S+] [PATTERN] list tables\n"));
256 0 : fprintf(output, _(" \\dT[S+] [PATTERN] list data types\n"));
257 0 : fprintf(output, _(" \\du[S+] [PATTERN] list roles\n"));
258 0 : fprintf(output, _(" \\dv[S+] [PATTERN] list views\n"));
259 0 : fprintf(output, _(" \\dx[+] [PATTERN] list extensions\n"));
260 0 : fprintf(output, _(" \\dy [PATTERN] list event triggers\n"));
261 0 : fprintf(output, _(" \\l[+] [PATTERN] list databases\n"));
262 0 : fprintf(output, _(" \\sf[+] FUNCNAME show a function's definition\n"));
263 0 : fprintf(output, _(" \\sv[+] VIEWNAME show a view's definition\n"));
264 0 : fprintf(output, _(" \\z [PATTERN] same as \\dp\n"));
265 0 : fprintf(output, "\n");
266 :
267 0 : fprintf(output, _("Formatting\n"));
268 0 : fprintf(output, _(" \\a toggle between unaligned and aligned output mode\n"));
269 0 : fprintf(output, _(" \\C [STRING] set table title, or unset if none\n"));
270 0 : fprintf(output, _(" \\f [STRING] show or set field separator for unaligned query output\n"));
271 0 : fprintf(output, _(" \\H toggle HTML output mode (currently %s)\n"),
272 0 : ON(pset.popt.topt.format == PRINT_HTML));
273 0 : fprintf(output, _(" \\pset [NAME [VALUE]] set table output option\n"
274 : " (NAME := {border|columns|expanded|fieldsep|fieldsep_zero|\n"
275 : " footer|format|linestyle|null|numericlocale|pager|\n"
276 : " pager_min_lines|recordsep|recordsep_zero|tableattr|title|\n"
277 : " tuples_only|unicode_border_linestyle|\n"
278 : " unicode_column_linestyle|unicode_header_linestyle})\n"));
279 0 : fprintf(output, _(" \\t [on|off] show only rows (currently %s)\n"),
280 0 : ON(pset.popt.topt.tuples_only));
281 0 : fprintf(output, _(" \\T [STRING] set HTML <table> tag attributes, or unset if none\n"));
282 0 : fprintf(output, _(" \\x [on|off|auto] toggle expanded output (currently %s)\n"),
283 0 : pset.popt.topt.expanded == 2 ? "auto" : ON(pset.popt.topt.expanded));
284 0 : fprintf(output, "\n");
285 :
286 0 : fprintf(output, _("Connection\n"));
287 0 : if (currdb)
288 0 : fprintf(output, _(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
289 : " connect to new database (currently \"%s\")\n"),
290 : currdb);
291 : else
292 0 : fprintf(output, _(" \\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}\n"
293 : " connect to new database (currently no connection)\n"));
294 0 : fprintf(output, _(" \\conninfo display information about current connection\n"));
295 0 : fprintf(output, _(" \\encoding [ENCODING] show or set client encoding\n"));
296 0 : fprintf(output, _(" \\password [USERNAME] securely change the password for a user\n"));
297 0 : fprintf(output, "\n");
298 :
299 0 : fprintf(output, _("Operating System\n"));
300 0 : fprintf(output, _(" \\cd [DIR] change the current working directory\n"));
301 0 : fprintf(output, _(" \\setenv NAME [VALUE] set or unset environment variable\n"));
302 0 : fprintf(output, _(" \\timing [on|off] toggle timing of commands (currently %s)\n"),
303 0 : ON(pset.timing));
304 0 : fprintf(output, _(" \\! [COMMAND] execute command in shell or start interactive shell\n"));
305 0 : fprintf(output, "\n");
306 :
307 0 : fprintf(output, _("Variables\n"));
308 0 : fprintf(output, _(" \\prompt [TEXT] NAME prompt user to set internal variable\n"));
309 0 : fprintf(output, _(" \\set [NAME [VALUE]] set internal variable, or list all if no parameters\n"));
310 0 : fprintf(output, _(" \\unset NAME unset (delete) internal variable\n"));
311 0 : fprintf(output, "\n");
312 :
313 0 : fprintf(output, _("Large Objects\n"));
314 0 : fprintf(output, _(" \\lo_export LOBOID FILE\n"
315 : " \\lo_import FILE [COMMENT]\n"
316 : " \\lo_list\n"
317 : " \\lo_unlink LOBOID large object operations\n"));
318 :
319 0 : ClosePager(output);
320 0 : }
321 :
322 :
323 : /*
324 : * helpVariables
325 : *
326 : * show list of available variables (options) from command line
327 : */
328 : void
329 0 : helpVariables(unsigned short int pager)
330 : {
331 : FILE *output;
332 :
333 : /*
334 : * Keep this line count in sync with the number of lines printed below!
335 : * Use "psql --help=variables | wc" to count correctly; but notice that
336 : * Windows builds currently print one more line than non-Windows builds.
337 : * Using the larger number is fine.
338 : */
339 0 : output = PageOutput(88, pager ? &(pset.popt.topt) : NULL);
340 :
341 0 : fprintf(output, _("List of specially treated variables\n\n"));
342 :
343 0 : fprintf(output, _("psql variables:\n"));
344 0 : fprintf(output, _("Usage:\n"));
345 0 : fprintf(output, _(" psql --set=NAME=VALUE\n or \\set NAME VALUE inside psql\n\n"));
346 :
347 0 : fprintf(output, _(" AUTOCOMMIT if set, successful SQL commands are automatically committed\n"));
348 0 : fprintf(output, _(" COMP_KEYWORD_CASE determines the case used to complete SQL key words\n"
349 : " [lower, upper, preserve-lower, preserve-upper]\n"));
350 0 : fprintf(output, _(" DBNAME the currently connected database name\n"));
351 0 : fprintf(output, _(" ECHO controls what input is written to standard output\n"
352 : " [all, errors, none, queries]\n"));
353 0 : fprintf(output, _(" ECHO_HIDDEN if set, display internal queries executed by backslash commands;\n"
354 : " if set to \"noexec\", just show without execution\n"));
355 0 : fprintf(output, _(" ENCODING current client character set encoding\n"));
356 0 : fprintf(output, _(" FETCH_COUNT the number of result rows to fetch and display at a time\n"
357 : " (default: 0=unlimited)\n"));
358 0 : fprintf(output, _(" HISTCONTROL controls command history [ignorespace, ignoredups, ignoreboth]\n"));
359 0 : fprintf(output, _(" HISTFILE file name used to store the command history\n"));
360 0 : fprintf(output, _(" HISTSIZE max number of commands to store in the command history\n"));
361 0 : fprintf(output, _(" HOST the currently connected database server host\n"));
362 0 : fprintf(output, _(" IGNOREEOF number of EOFs needed to terminate an interactive session\n"));
363 0 : fprintf(output, _(" LASTOID value of the last affected OID\n"));
364 0 : fprintf(output, _(" ON_ERROR_ROLLBACK if set, an error doesn't stop a transaction (uses implicit savepoints)\n"));
365 0 : fprintf(output, _(" ON_ERROR_STOP stop batch execution after error\n"));
366 0 : fprintf(output, _(" PORT server port of the current connection\n"));
367 0 : fprintf(output, _(" PROMPT1 specifies the standard psql prompt\n"));
368 0 : fprintf(output, _(" PROMPT2 specifies the prompt used when a statement continues from a previous line\n"));
369 0 : fprintf(output, _(" PROMPT3 specifies the prompt used during COPY ... FROM STDIN\n"));
370 0 : fprintf(output, _(" QUIET run quietly (same as -q option)\n"));
371 0 : fprintf(output, _(" SHOW_CONTEXT controls display of message context fields [never, errors, always]\n"));
372 0 : fprintf(output, _(" SINGLELINE end of line terminates SQL command mode (same as -S option)\n"));
373 0 : fprintf(output, _(" SINGLESTEP single-step mode (same as -s option)\n"));
374 0 : fprintf(output, _(" USER the currently connected database user\n"));
375 0 : fprintf(output, _(" VERBOSITY controls verbosity of error reports [default, verbose, terse]\n"));
376 :
377 0 : fprintf(output, _("\nDisplay settings:\n"));
378 0 : fprintf(output, _("Usage:\n"));
379 0 : fprintf(output, _(" psql --pset=NAME[=VALUE]\n or \\pset NAME [VALUE] inside psql\n\n"));
380 :
381 0 : fprintf(output, _(" border border style (number)\n"));
382 0 : fprintf(output, _(" columns target width for the wrapped format\n"));
383 0 : fprintf(output, _(" expanded (or x) expanded output [on, off, auto]\n"));
384 0 : fprintf(output, _(" fieldsep field separator for unaligned output (default \"%s\")\n"), DEFAULT_FIELD_SEP);
385 0 : fprintf(output, _(" fieldsep_zero set field separator for unaligned output to zero byte\n"));
386 0 : fprintf(output, _(" footer enable or disable display of the table footer [on, off]\n"));
387 0 : fprintf(output, _(" format set output format [unaligned, aligned, wrapped, html, asciidoc, ...]\n"));
388 0 : fprintf(output, _(" linestyle set the border line drawing style [ascii, old-ascii, unicode]\n"));
389 0 : fprintf(output, _(" null set the string to be printed in place of a null value\n"));
390 0 : fprintf(output, _(" numericlocale enable or disable display of a locale-specific character to separate\n"
391 : " groups of digits [on, off]\n"));
392 0 : fprintf(output, _(" pager control when an external pager is used [yes, no, always]\n"));
393 0 : fprintf(output, _(" recordsep record (line) separator for unaligned output\n"));
394 0 : fprintf(output, _(" recordsep_zero set record separator for unaligned output to zero byte\n"));
395 0 : fprintf(output, _(" tableattr (or T) specify attributes for table tag in html format or proportional\n"
396 : " column widths for left-aligned data types in latex-longtable format\n"));
397 0 : fprintf(output, _(" title set the table title for any subsequently printed tables\n"));
398 0 : fprintf(output, _(" tuples_only if set, only actual table data is shown\n"));
399 0 : fprintf(output, _(" unicode_border_linestyle\n"
400 : " unicode_column_linestyle\n"
401 : " unicode_header_linestyle\n"
402 : " set the style of Unicode line drawing [single, double]\n"));
403 :
404 0 : fprintf(output, _("\nEnvironment variables:\n"));
405 0 : fprintf(output, _("Usage:\n"));
406 :
407 : #ifndef WIN32
408 0 : fprintf(output, _(" NAME=VALUE [NAME=VALUE] psql ...\n or \\setenv NAME [VALUE] inside psql\n\n"));
409 : #else
410 : fprintf(output, _(" set NAME=VALUE\n psql ...\n or \\setenv NAME [VALUE] inside psql\n\n"));
411 : #endif
412 :
413 0 : fprintf(output, _(" COLUMNS number of columns for wrapped format\n"));
414 0 : fprintf(output, _(" PAGER name of external pager program\n"));
415 0 : fprintf(output, _(" PGAPPNAME same as the application_name connection parameter\n"));
416 0 : fprintf(output, _(" PGDATABASE same as the dbname connection parameter\n"));
417 0 : fprintf(output, _(" PGHOST same as the host connection parameter\n"));
418 0 : fprintf(output, _(" PGPASSWORD connection password (not recommended)\n"));
419 0 : fprintf(output, _(" PGPASSFILE password file name\n"));
420 0 : fprintf(output, _(" PGPORT same as the port connection parameter\n"));
421 0 : fprintf(output, _(" PGUSER same as the user connection parameter\n"));
422 0 : fprintf(output, _(" PSQL_EDITOR, EDITOR, VISUAL\n"
423 : " editor used by the \\e, \\ef, and \\ev commands\n"));
424 0 : fprintf(output, _(" PSQL_EDITOR_LINENUMBER_ARG\n"
425 : " how to specify a line number when invoking the editor\n"));
426 0 : fprintf(output, _(" PSQL_HISTORY alternative location for the command history file\n"));
427 0 : fprintf(output, _(" PSQLRC alternative location for the user's .psqlrc file\n"));
428 0 : fprintf(output, _(" SHELL shell used by the \\! command\n"));
429 0 : fprintf(output, _(" TMPDIR directory for temporary files\n"));
430 :
431 0 : ClosePager(output);
432 0 : }
433 :
434 :
435 : /*
436 : * helpSQL -- help with SQL commands
437 : *
438 : * Note: we assume caller removed any trailing spaces in "topic".
439 : */
440 : void
441 0 : helpSQL(const char *topic, unsigned short int pager)
442 : {
443 : #define VALUE_OR_NULL(a) ((a) ? (a) : "")
444 :
445 0 : if (!topic || strlen(topic) == 0)
446 0 : {
447 : /* Print all the available command names */
448 : int screen_width;
449 : int ncolumns;
450 : int nrows;
451 : FILE *output;
452 : int i;
453 : int j;
454 :
455 : #ifdef TIOCGWINSZ
456 : struct winsize screen_size;
457 :
458 0 : if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1)
459 0 : screen_width = 80; /* ioctl failed, assume 80 */
460 : else
461 0 : screen_width = screen_size.ws_col;
462 : #else
463 : screen_width = 80; /* default assumption */
464 : #endif
465 :
466 0 : ncolumns = (screen_width - 3) / (QL_MAX_CMD_LEN + 1);
467 0 : ncolumns = Max(ncolumns, 1);
468 0 : nrows = (QL_HELP_COUNT + (ncolumns - 1)) / ncolumns;
469 :
470 0 : output = PageOutput(nrows + 1, pager ? &(pset.popt.topt) : NULL);
471 :
472 0 : fputs(_("Available help:\n"), output);
473 :
474 0 : for (i = 0; i < nrows; i++)
475 : {
476 0 : fprintf(output, " ");
477 0 : for (j = 0; j < ncolumns - 1; j++)
478 0 : fprintf(output, "%-*s",
479 : QL_MAX_CMD_LEN + 1,
480 0 : VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd));
481 0 : if (i + j * nrows < QL_HELP_COUNT)
482 0 : fprintf(output, "%s",
483 0 : VALUE_OR_NULL(QL_HELP[i + j * nrows].cmd));
484 0 : fputc('\n', output);
485 : }
486 :
487 0 : ClosePager(output);
488 : }
489 : else
490 : {
491 : int i,
492 : j,
493 0 : x = 0;
494 0 : bool help_found = false;
495 0 : FILE *output = NULL;
496 : size_t len,
497 : wordlen;
498 0 : int nl_count = 0;
499 :
500 : /*
501 : * We first try exact match, then first + second words, then first
502 : * word only.
503 : */
504 0 : len = strlen(topic);
505 :
506 0 : for (x = 1; x <= 3; x++)
507 : {
508 0 : if (x > 1) /* Nothing on first pass - try the opening
509 : * word(s) */
510 : {
511 0 : wordlen = j = 1;
512 0 : while (topic[j] != ' ' && j++ < len)
513 0 : wordlen++;
514 0 : if (x == 2)
515 : {
516 0 : j++;
517 0 : while (topic[j] != ' ' && j++ <= len)
518 0 : wordlen++;
519 : }
520 0 : if (wordlen >= len) /* Don't try again if the same word */
521 : {
522 0 : if (!output)
523 0 : output = PageOutput(nl_count, pager ? &(pset.popt.topt) : NULL);
524 0 : break;
525 : }
526 0 : len = wordlen;
527 : }
528 :
529 : /* Count newlines for pager */
530 0 : for (i = 0; QL_HELP[i].cmd; i++)
531 : {
532 0 : if (pg_strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||
533 0 : strcmp(topic, "*") == 0)
534 : {
535 0 : nl_count += 5 + QL_HELP[i].nl_count;
536 :
537 : /* If we have an exact match, exit. Fixes \h SELECT */
538 0 : if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0)
539 0 : break;
540 : }
541 : }
542 :
543 0 : if (!output)
544 0 : output = PageOutput(nl_count, pager ? &(pset.popt.topt) : NULL);
545 :
546 0 : for (i = 0; QL_HELP[i].cmd; i++)
547 : {
548 0 : if (pg_strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||
549 0 : strcmp(topic, "*") == 0)
550 : {
551 : PQExpBufferData buffer;
552 :
553 0 : initPQExpBuffer(&buffer);
554 0 : QL_HELP[i].syntaxfunc(&buffer);
555 0 : help_found = true;
556 0 : fprintf(output, _("Command: %s\n"
557 : "Description: %s\n"
558 : "Syntax:\n%s\n\n"),
559 : QL_HELP[i].cmd,
560 : _(QL_HELP[i].help),
561 : buffer.data);
562 : /* If we have an exact match, exit. Fixes \h SELECT */
563 0 : if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0)
564 0 : break;
565 : }
566 : }
567 0 : if (help_found) /* Don't keep trying if we got a match */
568 0 : break;
569 : }
570 :
571 0 : if (!help_found)
572 0 : fprintf(output, _("No help available for \"%s\".\nTry \\h with no arguments to see available help.\n"), topic);
573 :
574 0 : ClosePager(output);
575 : }
576 0 : }
577 :
578 :
579 :
580 : void
581 0 : print_copyright(void)
582 : {
583 0 : puts(
584 : "PostgreSQL Database Management System\n"
585 : "(formerly known as Postgres, then as Postgres95)\n\n"
586 : "Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group\n\n"
587 : "Portions Copyright (c) 1994, The Regents of the University of California\n\n"
588 : "Permission to use, copy, modify, and distribute this software and its\n"
589 : "documentation for any purpose, without fee, and without a written agreement\n"
590 : "is hereby granted, provided that the above copyright notice and this\n"
591 : "paragraph and the following two paragraphs appear in all copies.\n\n"
592 : "IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR\n"
593 : "DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING\n"
594 : "LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS\n"
595 : "DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE\n"
596 : "POSSIBILITY OF SUCH DAMAGE.\n\n"
597 : "THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,\n"
598 : "INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\n"
599 : "AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS\n"
600 : "ON AN \"AS IS\" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO\n"
601 : "PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.\n"
602 : );
603 0 : }
|