27#include "catalog/pg_class_d.h"
71 bool active_branch,
const char *cmd);
80 bool show_verbose,
bool show_system);
141 const char *cmd,
bool is_func);
178 int lineno,
bool discard_on_quit,
bool *edited);
179static bool do_shell(
const char *command);
196static void checkWin32Codepage(
void);
240 Assert(scan_state != NULL);
252 if (
restricted && strcmp(cmd,
"unrestrict") != 0)
254 pg_log_error(
"backslash commands are restricted; only \\unrestrict is allowed");
258 status =
exec_command(cmd, scan_state, cstack, query_buf, previous_buf);
334 pg_log_warning(
"\\%s command ignored; use \\endif or Ctrl-C to exit current \\if block",
338 if (strcmp(cmd,
"a") == 0)
340 else if (strcmp(cmd,
"bind") == 0)
342 else if (strcmp(cmd,
"bind_named") == 0)
344 else if (strcmp(cmd,
"C") == 0)
346 else if (strcmp(cmd,
"c") == 0 || strcmp(cmd,
"connect") == 0)
348 else if (strcmp(cmd,
"cd") == 0)
350 else if (strcmp(cmd,
"close_prepared") == 0)
352 else if (strcmp(cmd,
"conninfo") == 0)
356 else if (strcmp(cmd,
"copyright") == 0)
358 else if (strcmp(cmd,
"crosstabview") == 0)
360 else if (cmd[0] ==
'd')
362 else if (strcmp(cmd,
"e") == 0 || strcmp(cmd,
"edit") == 0)
364 query_buf, previous_buf);
365 else if (strcmp(cmd,
"ef") == 0)
367 else if (strcmp(cmd,
"ev") == 0)
369 else if (strcmp(cmd,
"echo") == 0 || strcmp(cmd,
"qecho") == 0 ||
370 strcmp(cmd,
"warn") == 0)
372 else if (strcmp(cmd,
"elif") == 0)
374 else if (strcmp(cmd,
"else") == 0)
376 else if (strcmp(cmd,
"endif") == 0)
378 else if (strcmp(cmd,
"endpipeline") == 0)
380 else if (strcmp(cmd,
"encoding") == 0)
382 else if (strcmp(cmd,
"errverbose") == 0)
384 else if (strcmp(cmd,
"f") == 0)
386 else if (strcmp(cmd,
"flush") == 0)
388 else if (strcmp(cmd,
"flushrequest") == 0)
390 else if (strcmp(cmd,
"g") == 0 || strcmp(cmd,
"gx") == 0)
392 else if (strcmp(cmd,
"gdesc") == 0)
394 else if (strcmp(cmd,
"getenv") == 0)
396 else if (strcmp(cmd,
"getresults") == 0)
398 else if (strcmp(cmd,
"gexec") == 0)
400 else if (strcmp(cmd,
"gset") == 0)
402 else if (strcmp(cmd,
"h") == 0 || strcmp(cmd,
"help") == 0)
404 else if (strcmp(cmd,
"H") == 0 || strcmp(cmd,
"html") == 0)
406 else if (strcmp(cmd,
"i") == 0 || strcmp(cmd,
"include") == 0 ||
407 strcmp(cmd,
"ir") == 0 || strcmp(cmd,
"include_relative") == 0)
409 else if (strcmp(cmd,
"if") == 0)
411 else if (strcmp(cmd,
"l") == 0 || strcmp(cmd,
"list") == 0 ||
412 strcmp(cmd,
"lx") == 0 || strcmp(cmd,
"listx") == 0 ||
413 strcmp(cmd,
"l+") == 0 || strcmp(cmd,
"list+") == 0 ||
414 strcmp(cmd,
"lx+") == 0 || strcmp(cmd,
"listx+") == 0 ||
415 strcmp(cmd,
"l+x") == 0 || strcmp(cmd,
"list+x") == 0)
417 else if (strncmp(cmd,
"lo_", 3) == 0)
419 else if (strcmp(cmd,
"o") == 0 || strcmp(cmd,
"out") == 0)
421 else if (strcmp(cmd,
"p") == 0 || strcmp(cmd,
"print") == 0)
423 query_buf, previous_buf);
424 else if (strcmp(cmd,
"parse") == 0)
426 else if (strcmp(cmd,
"password") == 0)
428 else if (strcmp(cmd,
"prompt") == 0)
430 else if (strcmp(cmd,
"pset") == 0)
432 else if (strcmp(cmd,
"q") == 0 || strcmp(cmd,
"quit") == 0)
434 else if (strcmp(cmd,
"r") == 0 || strcmp(cmd,
"reset") == 0)
436 else if (strcmp(cmd,
"restrict") == 0)
438 else if (strcmp(cmd,
"s") == 0)
440 else if (strcmp(cmd,
"sendpipeline") == 0)
442 else if (strcmp(cmd,
"set") == 0)
444 else if (strcmp(cmd,
"setenv") == 0)
446 else if (strcmp(cmd,
"sf") == 0 || strcmp(cmd,
"sf+") == 0)
448 else if (strcmp(cmd,
"sv") == 0 || strcmp(cmd,
"sv+") == 0)
450 else if (strcmp(cmd,
"startpipeline") == 0)
452 else if (strcmp(cmd,
"syncpipeline") == 0)
454 else if (strcmp(cmd,
"t") == 0)
456 else if (strcmp(cmd,
"T") == 0)
458 else if (strcmp(cmd,
"timing") == 0)
460 else if (strcmp(cmd,
"unrestrict") == 0)
462 else if (strcmp(cmd,
"unset") == 0)
464 else if (strcmp(cmd,
"w") == 0 || strcmp(cmd,
"write") == 0)
466 query_buf, previous_buf);
467 else if (strcmp(cmd,
"watch") == 0)
469 query_buf, previous_buf);
470 else if (strcmp(cmd,
"x") == 0)
472 else if (strcmp(cmd,
"z") == 0 ||
473 strcmp(cmd,
"zS") == 0 || strcmp(cmd,
"zx") == 0 ||
474 strcmp(cmd,
"zSx") == 0 || strcmp(cmd,
"zxS") == 0)
476 else if (strcmp(cmd,
"!") == 0)
478 else if (strcmp(cmd,
"?") == 0)
535 if (nparams > nalloc)
537 nalloc = nalloc ? nalloc * 2 : 1;
585 if (nparams > nalloc)
587 nalloc = nalloc ? nalloc * 2 : 1;
644 static const char prefix[] =
"-reuse-previous=";
652 if (opt1 != NULL && strncmp(opt1, prefix,
sizeof(prefix) - 1) == 0)
707 dir = getenv(
"HOME");
708 if (dir == NULL || dir[0] ==
'\0')
710 uid_t user_id = geteuid();
714 pw = getpwuid(user_id);
719 pg_log_error(
"could not get home directory for user ID %ld: %s",
721 errno ?
strerror(errno) :
_(
"user does not exist"));
738 pg_log_error(
"\\%s: could not change directory to \"%s\": %m",
797 char *protocol_version,
811 printf(
_(
"You are currently not connected to a database.\n"));
819 protocol_version =
psprintf(
"%d.%d", version_num / 10000,
820 version_num % 10000);
828 hostaddr && *hostaddr && strcmp(host, hostaddr) != 0);
855 if (hostaddr && *hostaddr)
936 _(
"true") :
_(
"false"),
false,
false);
953 pfree(protocol_version);
1031 unsigned short int save_expanded;
1037 show_verbose = strchr(cmd,
'+') ?
true :
false;
1038 show_system = strchr(cmd,
'S') ?
true :
false;
1047 if (cmd[1] !=
'\0' && strchr(&cmd[2],
'x'))
1063 char *pattern2 = NULL;
1065 if (pattern && cmd[2] !=
'\0' && cmd[2] !=
'+' && cmd[2] !=
'x')
1102 if (strncmp(cmd,
"dconfig", 7) == 0)
1115 if (strncmp(cmd,
"ddp", 3) == 0)
1136 show_verbose, show_system);
1158 show_verbose, show_system);
1196 if (cmd[2] ==
'd' && cmd[3] ==
's')
1198 char *pattern2 = NULL;
1207 else if (cmd[2] ==
'g')
1306 const char *pattern,
1307 bool show_verbose,
bool show_system)
1311 int num_arg_patterns = 0;
1321 arg_patterns[num_arg_patterns++] = ap;
1329 arg_patterns, num_arg_patterns,
1330 show_verbose, show_system);
1333 arg_patterns, num_arg_patterns,
1334 show_verbose, show_system);
1336 while (--num_arg_patterns >= 0)
1337 free(arg_patterns[num_arg_patterns]);
1376 strspn(fname,
"0123456789") == strlen(fname))
1395 bool discard_on_quit;
1402 discard_on_quit =
true;
1415 if (
do_edit(fname, query_buf, lineno, discard_on_quit, NULL))
1477 "CREATE FUNCTION ( )\n"
1480 " -- common options: IMMUTABLE STABLE STRICT SECURITY DEFINER\n"
1487 " -- something...\n");
1499 else if (is_func && lineno > 0)
1510 const char *lines = query_buf->
data;
1512 while (*lines !=
'\0')
1514 if (strncmp(lines,
"AS ", 3) == 0 ||
1515 strncmp(lines,
"BEGIN ", 6) == 0 ||
1516 strncmp(lines,
"RETURN ", 7) == 0)
1520 lines = strchr(lines,
'\n');
1530 bool edited =
false;
1532 if (!
do_edit(NULL, query_buf, lineno,
true, &edited))
1535 puts(
_(
"No changes"));
1565 bool no_newline =
false;
1569 if (strcmp(cmd,
"qecho") == 0)
1571 else if (strcmp(cmd,
"warn") == 0)
1579 if (first && !no_newline && !quoted && strcmp(
value,
"-n") == 0)
1660 puts(
_(
"out of memory"));
1663 puts(
_(
"There is no previous error."));
1751 if (fname && fname[0] ==
'(')
1755 active_branch, cmd);
1766 pg_log_error(
"\\%s not allowed in pipeline mode", cmd);
1779 if (strcmp(cmd,
"gx") == 0)
1801 bool active_branch,
const char *cmd)
1804 bool found_r_paren =
false;
1831 if (optlen > 0 &&
option[optlen - 1] ==
')')
1834 found_r_paren =
true;
1841 char *valptr = strchr(
option,
'=');
1856 first_option = NULL;
1859 }
while (!found_r_paren);
1904 if (!myvar || !envvar)
1911 char *envval = getenv(envvar);
1945 num_results = atoi(opt);
1946 if (num_results < 0)
1948 pg_log_error(
"\\getresults: invalid number of requested results");
1973 pg_log_error(
"\\%s not allowed in pipeline mode",
"gexec");
1999 pg_log_error(
"\\%s not allowed in pipeline mode",
"gset");
2079 bool include_relative;
2081 include_relative = (strcmp(cmd,
"ir") == 0
2082 || strcmp(cmd,
"include_relative") == 0);
2339 unsigned short int save_expanded;
2344 show_verbose = strchr(cmd,
'+') ?
true :
false;
2348 if (strchr(cmd,
'x'))
2383 if (strcmp(cmd + 3,
"export") == 0)
2397 else if (strcmp(cmd + 3,
"import") == 0)
2411 else if (strncmp(cmd + 3,
"list", 4) == 0)
2414 unsigned short int save_expanded;
2416 show_verbose = strchr(cmd,
'+') ?
true :
false;
2420 if (strchr(cmd,
'x'))
2429 else if (strcmp(cmd + 3,
"unlink") == 0)
2492 if (query_buf && query_buf->
len > 0)
2493 puts(query_buf->
data);
2494 else if (previous_buf && previous_buf->
len > 0)
2495 puts(previous_buf->
data);
2497 puts(
_(
"Query buffer is empty."));
2560 res =
PSQLexec(
"SELECT CURRENT_USER");
2585 else if (strcmp(pw1, pw2) != 0)
2626 *prompt_text = NULL;
2664 fputs(prompt_text,
stdout);
2670 pg_log_error(
"\\%s: could not read value for variable",
2711 static const char *
const my_list[] = {
2712 "border",
"columns",
"csv_fieldsep",
2713 "display_false",
"display_true",
"expanded",
"fieldsep",
2714 "fieldsep_zero",
"footer",
"format",
"linestyle",
"null",
2715 "numericlocale",
"pager",
"pager_min_lines",
2716 "recordsep",
"recordsep_zero",
2717 "tableattr",
"title",
"tuples_only",
2718 "unicode_border_linestyle",
2719 "unicode_column_linestyle",
2720 "unicode_header_linestyle",
2725 for (
i = 0; my_list[
i] != NULL;
i++)
2773 puts(
_(
"Query buffer reset (cleared)."));
2793 if (opt == NULL || opt[0] ==
'\0')
2824 printf(
_(
"Wrote history to file \"%s\".\n"), fname);
2854 pg_log_error(
"\\sendpipeline must be used after \\bind or \\bind_named");
2861 pg_log_error(
"\\sendpipeline not allowed outside of pipeline mode");
2946 else if (strchr(envvar,
'=') != NULL)
2948 pg_log_error(
"\\%s: environment variable name must not contain \"=\"",
2961 setenv(envvar, envval, 1);
2978 const char *cmd,
bool is_func)
2984 bool show_linenumbers = (strchr(cmd,
'+') != NULL);
3032 if (show_linenumbers)
3177 puts(
_(
"Timing is on."));
3179 puts(
_(
"Timing is off."));
3201 if (opt == NULL || opt[0] ==
'\0')
3209 pg_log_error(
"\\%s: not currently in restricted mode", cmd);
3274 bool is_pipe =
false;
3291 if (fname[0] ==
'|')
3296 fd = popen(&fname[1],
"w");
3301 fd = fopen(fname,
"w");
3321 if (query_buf && query_buf->
len > 0)
3323 else if (previous_buf && previous_buf->
len > 0)
3328 result = pclose(
fd);
3339 result = fclose(
fd);
3372 bool have_sleep =
false;
3373 bool have_iter =
false;
3374 bool have_min_rows =
false;
3381 pg_log_error(
"\\%s not allowed in pipeline mode",
"watch");
3403 valptr = strchr(opt,
'=');
3408 if (strncmp(
"i=", opt, strlen(
"i=")) == 0 ||
3409 strncmp(
"interval=", opt, strlen(
"interval=")) == 0)
3413 pg_log_error(
"\\watch: interval value is specified more than once");
3420 sleep = strtod(valptr, &opt_end);
3421 if (sleep < 0 || *opt_end || errno == ERANGE)
3423 pg_log_error(
"\\watch: incorrect interval value \"%s\"", valptr);
3428 else if (strncmp(
"c=", opt, strlen(
"c=")) == 0 ||
3429 strncmp(
"count=", opt, strlen(
"count=")) == 0)
3433 pg_log_error(
"\\watch: iteration count is specified more than once");
3440 iter =
strtoint(valptr, &opt_end, 10);
3441 if (iter <= 0 || *opt_end || errno == ERANGE)
3443 pg_log_error(
"\\watch: incorrect iteration count \"%s\"", valptr);
3448 else if (strncmp(
"m=", opt, strlen(
"m=")) == 0 ||
3449 strncmp(
"min_rows=", opt, strlen(
"min_rows=")) == 0)
3453 pg_log_error(
"\\watch: minimum row count specified more than once");
3458 have_min_rows =
true;
3460 min_rows =
strtoint(valptr, &opt_end, 10);
3461 if (min_rows <= 0 || *opt_end || errno == ERANGE)
3463 pg_log_error(
"\\watch: incorrect minimum row count \"%s\"", valptr);
3470 pg_log_error(
"\\watch: unrecognized parameter \"%s\"", opt);
3479 pg_log_error(
"\\watch: interval value is specified more than once");
3486 sleep = strtod(opt, &opt_end);
3487 if (sleep < 0 || *opt_end || errno == ERANGE)
3489 pg_log_error(
"\\watch: incorrect interval value \"%s\"", opt);
3551 unsigned short int save_expanded;
3556 show_system = strchr(cmd,
'S') ?
true :
false;
3560 if (strchr(cmd,
'x'))
3609 if (!opt0 || strcmp(opt0,
"commands") == 0)
3611 else if (strcmp(opt0,
"options") == 0)
3613 else if (strcmp(opt0,
"variables") == 0)
3655 if (*result ==
'\0' || strcmp(result,
"-") == 0)
3676 int num_options = 0;
3684 if (num_options > 0)
3787 return (strcmp(cmd,
"if") == 0 ||
3788 strcmp(cmd,
"elif") == 0 ||
3789 strcmp(cmd,
"else") == 0 ||
3790 strcmp(cmd,
"endif") == 0);
3828 Assert(new_len >= 0 && new_len <= query_buf->
len);
3829 query_buf->
len = new_len;
3830 query_buf->
data[new_len] =
'\0';
3849 if (query_buf && query_buf->
len == 0)
3895 if (new_val == NULL)
3898 if (old_val == NULL || strcmp(old_val, new_val) != 0)
3923 bool same_host =
false;
3925 char *client_encoding;
3927 bool keep_password =
true;
3928 bool has_connection_string;
3929 bool reuse_previous;
3931 has_connection_string =
dbname ?
3935 if (has_connection_string && (
user || host ||
port))
3937 pg_log_error(
"Do not give user, host, or port separately when using a connection string");
3941 switch (reuse_previous_specification)
3944 reuse_previous =
true;
3947 reuse_previous =
false;
3950 reuse_previous = !has_connection_string;
3972 pg_log_error(
"No database connection exists to re-use parameters from");
3981 if (has_connection_string)
3992 bool have_password =
false;
3994 for (ci = cinfo, replci = replcinfo;
4007 char *swap = replci->
val;
4019 if (replci->
val == NULL ||
4020 strcmp(ci->
val, replci->
val) != 0)
4022 if (strcmp(replci->
keyword,
"user") == 0 ||
4023 strcmp(replci->
keyword,
"host") == 0 ||
4024 strcmp(replci->
keyword,
"hostaddr") == 0 ||
4025 strcmp(replci->
keyword,
"port") == 0)
4026 keep_password =
false;
4029 if (strcmp(replci->
keyword,
"password") == 0)
4030 have_password =
true;
4032 else if (!reuse_previous)
4055 nconnopts = ci - cinfo;
4065 keep_password =
true;
4100 for (ci = cinfo; ci->
keyword; ci++)
4104 if (!(ci->
val && strcmp(
user, ci->
val) == 0))
4105 keep_password =
false;
4107 else if (host && strcmp(ci->
keyword,
"host") == 0)
4109 if (ci->
val && strcmp(host, ci->
val) == 0)
4112 keep_password =
false;
4114 else if (
port && strcmp(ci->
keyword,
"port") == 0)
4116 if (!(ci->
val && strcmp(
port, ci->
val) == 0))
4117 keep_password =
false;
4122 nconnopts = ci - cinfo;
4144 bool canceled =
false;
4163 if (
pset.
notty || getenv(
"PGCLIENTENCODING"))
4164 client_encoding = NULL;
4166 client_encoding =
"auto";
4185 for (ci = cinfo; ci->
keyword; ci++)
4191 else if (
user && strcmp(ci->
keyword,
"user") == 0)
4193 else if (host && strcmp(ci->
keyword,
"host") == 0)
4194 values[paramnum++] = host;
4195 else if (host && !same_host && strcmp(ci->
keyword,
"hostaddr") == 0)
4198 values[paramnum++] = NULL;
4200 else if (
port && strcmp(ci->
keyword,
"port") == 0)
4203 else if ((
password || !keep_password) &&
4204 strcmp(ci->
keyword,
"password") == 0)
4206 else if (strcmp(ci->
keyword,
"fallback_application_name") == 0)
4208 else if (client_encoding &&
4209 strcmp(ci->
keyword,
"client_encoding") == 0)
4210 values[paramnum++] = client_encoding;
4235 bool canceled =
false;
4340 if (hostaddr && *hostaddr)
4341 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" on address \"%s\" at port \"%s\".\n"),
4344 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" via socket in \"%s\" at port \"%s\".\n"),
4349 if (hostaddr && *hostaddr && strcmp(connhost, hostaddr) != 0)
4350 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" on host \"%s\" (address \"%s\") at port \"%s\".\n"),
4353 printf(
_(
"You are now connected to database \"%s\" as user \"%s\" on host \"%s\" at port \"%s\".\n"),
4358 printf(
_(
"You are now connected to database \"%s\" as user \"%s\".\n"),
4382 bool forRead =
false;
4446 int client_ver = PG_VERSION_NUM;
4460 sverbuf,
sizeof(sverbuf));
4464 printf(
_(
"%s (%s, server %s)\n"),
4468 else if (in_startup)
4477 printf(
_(
"WARNING: %s major version %s, server major version %s.\n"
4478 " Some psql features might not work.\n"),
4481 cverbuf,
sizeof(cverbuf)),
4483 sverbuf,
sizeof(sverbuf)));
4487 checkWin32Codepage();
4503 const char *protocol;
4505 const char *compression;
4516 printf(
_(
"SSL connection (protocol: %s, cipher: %s, compression: %s, ALPN: %s)\n"),
4517 protocol ? protocol :
_(
"unknown"),
4518 cipher ? cipher :
_(
"unknown"),
4519 (compression && strcmp(compression,
"off") != 0) ?
_(
"on") :
_(
"off"),
4520 (alpn && alpn[0] !=
'\0') ? alpn :
_(
"none"));
4534 printf(
_(
"GSSAPI-encrypted connection\n"));
4545checkWin32Codepage(
void)
4551 concp = GetConsoleCP();
4554 printf(
_(
"WARNING: Console code page (%u) differs from Windows code page (%u)\n"
4555 " 8-bit characters might not work correctly. See psql reference\n"
4556 " page \"Notes for Windows users\" for details.\n"),
4649 const char *editorName;
4650 const char *editor_lineno_arg = NULL;
4657 editorName = getenv(
"PSQL_EDITOR");
4659 editorName = getenv(
"EDITOR");
4661 editorName = getenv(
"VISUAL");
4668 editor_lineno_arg = getenv(
"PSQL_EDITOR_LINENUMBER_ARG");
4669#ifdef DEFAULT_EDITOR_LINENUMBER_ARG
4670 if (!editor_lineno_arg)
4673 if (!editor_lineno_arg)
4675 pg_log_error(
"environment variable PSQL_EDITOR_LINENUMBER_ARG must be set to specify a line number");
4689 sys =
psprintf(
"exec %s %s%d '%s'",
4690 editorName, editor_lineno_arg, lineno, fname);
4696 sys =
psprintf(
"\"%s\" %s%d \"%s\"",
4697 editorName, editor_lineno_arg, lineno, fname);
4703 result = system(sys);
4705 pg_log_error(
"could not start editor \"%s\"", editorName);
4706 else if (result == 127)
4730 int lineno,
bool discard_on_quit,
bool *edited)
4733 FILE *stream = NULL;
4741 fname = filename_arg;
4746 const char *tmpdir = getenv(
"TMPDIR");
4757 pg_log_error(
"could not locate temporary directory: %s",
4769 snprintf(fnametmp,
sizeof(fnametmp),
"%s%spsql.edit.%d.sql", tmpdir,
4770 "/", (
int) getpid());
4772 snprintf(fnametmp,
sizeof(fnametmp),
"%s%spsql.edit.%d.sql", tmpdir,
4773 "" , (
int) getpid());
4776 fname = (
const char *) fnametmp;
4778 fd = open(fname, O_WRONLY | O_CREAT | O_EXCL, 0600);
4780 stream = fdopen(
fd,
"w");
4782 if (
fd == -1 || !stream)
4784 pg_log_error(
"could not open temporary file \"%s\": %m", fname);
4789 unsigned int ql = query_buf->
len;
4792 if (ql > 0 && query_buf->
data[ql - 1] !=
'\n')
4798 if (fwrite(query_buf->
data, 1, ql, stream) != ql)
4802 if (fclose(stream) != 0)
4805 if (remove(fname) != 0)
4810 else if (fclose(stream) != 0)
4813 if (remove(fname) != 0)
4832 ut.modtime = ut.actime = time(NULL) - 2;
4833 (void) utime(fname, &ut);
4871 while (fgets(line,
sizeof(line), stream) != NULL)
4894 if (discard_on_quit)
4901 if (remove(fname) == -1)
4936 else if (strcmp(
filename,
"-") != 0)
5014 return "latex-longtable";
5084 vallen = strlen(
value);
5087 if (strcmp(param,
"format") == 0)
5089 static const struct fmt
5120 pg_log_error(
"\\pset: ambiguous abbreviation \"%s\" matches both \"%s\" and \"%s\"",
5122 formats[match_pos].
name, formats[
i].
name);
5128 popt->
topt.
format = formats[match_pos].number;
5140 pg_log_error(
"\\pset: allowed formats are aligned, asciidoc, csv, html, latex, latex-longtable, troff-ms, unaligned, wrapped");
5147 else if (strcmp(param,
"linestyle") == 0)
5159 pg_log_error(
"\\pset: allowed line styles are ascii, old-ascii, unicode");
5165 else if (strcmp(param,
"unicode_border_linestyle") == 0)
5174 pg_log_error(
"\\pset: allowed Unicode border line styles are single, double");
5180 else if (strcmp(param,
"unicode_column_linestyle") == 0)
5189 pg_log_error(
"\\pset: allowed Unicode column line styles are single, double");
5195 else if (strcmp(param,
"unicode_header_linestyle") == 0)
5204 pg_log_error(
"\\pset: allowed Unicode header line styles are single, double");
5210 else if (strcmp(param,
"border") == 0)
5217 else if (strcmp(param,
"x") == 0 ||
5218 strcmp(param,
"expanded") == 0 ||
5219 strcmp(param,
"vertical") == 0)
5240 else if (strcmp(param,
"xheader_width") == 0)
5252 int intval = atoi(
value);
5256 pg_log_error(
"\\pset: allowed xheader_width values are \"%s\" (default), \"%s\", \"%s\", or a number specifying the exact width",
"full",
"column",
"page");
5266 else if (strcmp(param,
"csv_fieldsep") == 0)
5271 if (strlen(
value) != 1)
5273 pg_log_error(
"\\pset: csv_fieldsep must be a single one-byte character");
5278 pg_log_error(
"\\pset: csv_fieldsep cannot be a double quote, a newline, or a carriage return");
5286 else if (strcmp(param,
"numericlocale") == 0)
5295 else if (strcmp(param,
"null") == 0)
5305 else if (strcmp(param,
"display_false") == 0)
5315 else if (strcmp(param,
"display_true") == 0)
5325 else if (strcmp(param,
"fieldsep") == 0)
5335 else if (strcmp(param,
"fieldsep_zero") == 0)
5343 else if (strcmp(param,
"recordsep") == 0)
5353 else if (strcmp(param,
"recordsep_zero") == 0)
5361 else if (strcmp(param,
"t") == 0 || strcmp(param,
"tuples_only") == 0)
5370 else if (strcmp(param,
"C") == 0 || strcmp(param,
"title") == 0)
5380 else if (strcmp(param,
"T") == 0 || strcmp(param,
"tableattr") == 0)
5390 else if (strcmp(param,
"pager") == 0)
5412 else if (strcmp(param,
"pager_min_lines") == 0)
5420 else if (strcmp(param,
"footer") == 0)
5429 else if (strcmp(param,
"columns") == 0)
5455 if (strcmp(param,
"border") == 0)
5459 else if (strcmp(param,
"columns") == 0)
5462 printf(
_(
"Target width is unset.\n"));
5468 else if (strcmp(param,
"x") == 0 || strcmp(param,
"expanded") == 0 || strcmp(param,
"vertical") == 0)
5471 printf(
_(
"Expanded display is on.\n"));
5473 printf(
_(
"Expanded display is used automatically.\n"));
5475 printf(
_(
"Expanded display is off.\n"));
5479 else if (strcmp(param,
"xheader_width") == 0)
5482 printf(
_(
"Expanded header width is \"%s\".\n"),
"full");
5484 printf(
_(
"Expanded header width is \"%s\".\n"),
"column");
5486 printf(
_(
"Expanded header width is \"%s\".\n"),
"page");
5492 else if (strcmp(param,
"csv_fieldsep") == 0)
5494 printf(
_(
"Field separator for CSV is \"%s\".\n"),
5499 else if (strcmp(param,
"display_false") == 0)
5501 printf(
_(
"Boolean false display is \"%s\".\n"),
5506 else if (strcmp(param,
"display_true") == 0)
5508 printf(
_(
"Boolean true display is \"%s\".\n"),
5513 else if (strcmp(param,
"fieldsep") == 0)
5516 printf(
_(
"Field separator is zero byte.\n"));
5518 printf(
_(
"Field separator is \"%s\".\n"),
5522 else if (strcmp(param,
"fieldsep_zero") == 0)
5524 printf(
_(
"Field separator is zero byte.\n"));
5528 else if (strcmp(param,
"footer") == 0)
5531 printf(
_(
"Default footer is on.\n"));
5533 printf(
_(
"Default footer is off.\n"));
5537 else if (strcmp(param,
"format") == 0)
5543 else if (strcmp(param,
"linestyle") == 0)
5545 printf(
_(
"Line style is %s.\n"),
5550 else if (strcmp(param,
"null") == 0)
5552 printf(
_(
"Null display is \"%s\".\n"),
5557 else if (strcmp(param,
"numericlocale") == 0)
5560 printf(
_(
"Locale-adjusted numeric output is on.\n"));
5562 printf(
_(
"Locale-adjusted numeric output is off.\n"));
5566 else if (strcmp(param,
"pager") == 0)
5569 printf(
_(
"Pager is used for long output.\n"));
5571 printf(
_(
"Pager is always used.\n"));
5573 printf(
_(
"Pager usage is off.\n"));
5577 else if (strcmp(param,
"pager_min_lines") == 0)
5580 "Pager won't be used for less than %d lines.\n",
5586 else if (strcmp(param,
"recordsep") == 0)
5589 printf(
_(
"Record separator is zero byte.\n"));
5591 printf(
_(
"Record separator is <newline>.\n"));
5593 printf(
_(
"Record separator is \"%s\".\n"),
5597 else if (strcmp(param,
"recordsep_zero") == 0)
5599 printf(
_(
"Record separator is zero byte.\n"));
5603 else if (strcmp(param,
"T") == 0 || strcmp(param,
"tableattr") == 0)
5606 printf(
_(
"Table attributes are \"%s\".\n"),
5609 printf(
_(
"Table attributes unset.\n"));
5613 else if (strcmp(param,
"C") == 0 || strcmp(param,
"title") == 0)
5618 printf(
_(
"Title is unset.\n"));
5622 else if (strcmp(param,
"t") == 0 || strcmp(param,
"tuples_only") == 0)
5625 printf(
_(
"Tuples only is on.\n"));
5627 printf(
_(
"Tuples only is off.\n"));
5631 else if (strcmp(param,
"unicode_border_linestyle") == 0)
5633 printf(
_(
"Unicode border line style is \"%s\".\n"),
5637 else if (strcmp(param,
"unicode_column_linestyle") == 0)
5639 printf(
_(
"Unicode column line style is \"%s\".\n"),
5643 else if (strcmp(param,
"unicode_header_linestyle") == 0)
5645 printf(
_(
"Unicode header line style is \"%s\".\n"),
5728 return val ?
"on" :
"off";
5747 else if (*
str ==
'\'')
5775 if (strcmp(param,
"border") == 0)
5777 else if (strcmp(param,
"columns") == 0)
5779 else if (strcmp(param,
"csv_fieldsep") == 0)
5781 else if (strcmp(param,
"display_false") == 0)
5783 else if (strcmp(param,
"display_true") == 0)
5785 else if (strcmp(param,
"expanded") == 0)
5789 else if (strcmp(param,
"fieldsep") == 0)
5793 else if (strcmp(param,
"fieldsep_zero") == 0)
5795 else if (strcmp(param,
"footer") == 0)
5797 else if (strcmp(param,
"format") == 0)
5799 else if (strcmp(param,
"linestyle") == 0)
5801 else if (strcmp(param,
"null") == 0)
5805 else if (strcmp(param,
"numericlocale") == 0)
5807 else if (strcmp(param,
"pager") == 0)
5809 else if (strcmp(param,
"pager_min_lines") == 0)
5811 else if (strcmp(param,
"recordsep") == 0)
5815 else if (strcmp(param,
"recordsep_zero") == 0)
5817 else if (strcmp(param,
"tableattr") == 0)
5819 else if (strcmp(param,
"title") == 0)
5821 else if (strcmp(param,
"tuples_only") == 0)
5823 else if (strcmp(param,
"unicode_border_linestyle") == 0)
5825 else if (strcmp(param,
"unicode_column_linestyle") == 0)
5827 else if (strcmp(param,
"unicode_header_linestyle") == 0)
5829 else if (strcmp(param,
"xheader_width") == 0)
5842 snprintf(wbuff,
sizeof(wbuff),
"%d",
5854#define DEFAULT_SHELL "/bin/sh"
5860#define DEFAULT_SHELL "cmd.exe"
5872 const char *shellName;
5874 shellName = getenv(
"SHELL");
5876 if (shellName == NULL)
5877 shellName = getenv(
"COMSPEC");
5879 if (shellName == NULL)
5884 sys =
psprintf(
"exec %s", shellName);
5886 sys =
psprintf(
"\"%s\"", shellName);
5888 result = system(sys);
5892 result = system(command);
5896 if (result == 127 || result == -1)
5917 long sleep_ms = (long) (sleep * 1000);
5919 const char *strftime_fmt;
5920 const char *user_title;
5922 const char *pagerprog = NULL;
5923 FILE *pagerpipe = NULL;
5928 sigset_t sigalrm_sigchld_sigint;
5929 sigset_t sigalrm_sigchld;
5934 if (!query_buf || query_buf->
len <= 0)
5936 pg_log_error(
"\\watch cannot be used with an empty query");
5941 sigemptyset(&sigalrm_sigchld_sigint);
5942 sigaddset(&sigalrm_sigchld_sigint,
SIGCHLD);
5943 sigaddset(&sigalrm_sigchld_sigint,
SIGALRM);
5944 sigaddset(&sigalrm_sigchld_sigint, SIGINT);
5946 sigemptyset(&sigalrm_sigchld);
5947 sigaddset(&sigalrm_sigchld,
SIGCHLD);
5948 sigaddset(&sigalrm_sigchld,
SIGALRM);
5950 sigemptyset(&sigint);
5951 sigaddset(&sigint, SIGINT);
5957 sigprocmask(SIG_BLOCK, &sigalrm_sigchld, NULL);
5982 pagerprog = getenv(
"PSQL_WATCH_PAGER");
5984 if (pagerprog && strspn(pagerprog,
" \t\r\n") == strlen(pagerprog))
5988 isatty(fileno(stdin)) && isatty(fileno(
stdout)))
5992 pagerpipe = popen(pagerprog,
"w");
6004 strftime_fmt =
"%c";
6018 user_title = myopt.
title;
6019 title_len = (user_title ? strlen(user_title) : 0) + 256;
6034 strftime(timebuf,
sizeof(timebuf), strftime_fmt, localtime(&timer));
6037 snprintf(title, title_len,
_(
"%s\t%s (every %gs)\n"),
6038 user_title, timebuf,
sleep_ms / 1000.0);
6040 snprintf(title, title_len,
_(
"%s (every %gs)\n"),
6042 myopt.
title = title;
6055 if (iter && (--iter <= 0))
6059 if (pagerpipe && ferror(pagerpipe))
6075 long s =
Min(
i, 1000L);
6087 sigprocmask(SIG_BLOCK, &sigint, NULL);
6094 int signal_received;
6096 errno = sigwait(&sigalrm_sigchld_sigint, &signal_received);
6110 if (signal_received == SIGINT || signal_received ==
SIGCHLD)
6117 sigprocmask(SIG_UNBLOCK, &sigint, NULL);
6144 sigprocmask(SIG_UNBLOCK, &sigalrm_sigchld_sigint, NULL);
6160 printf(
_(
"/******** QUERY *********/\n"
6162 "/************************/\n\n"), query);
6167 _(
"/******** QUERY *********/\n"
6169 "/************************/\n\n"), query);
6207 strchr(desc,
'(') ?
"regprocedure" :
"regproc");
6259 "SELECT pg_catalog.pg_get_functiondef(%u)",
6280 "SELECT nspname, relname, relkind, "
6281 "pg_catalog.pg_get_viewdef(c.oid, true), "
6282 "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
6283 "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text "
6284 "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption "
6285 "FROM pg_catalog.pg_class c "
6286 "LEFT JOIN pg_catalog.pg_namespace n "
6287 "ON c.relnamespace = n.oid WHERE c.oid = %u",
6293 "SELECT nspname, relname, relkind, "
6294 "pg_catalog.pg_get_viewdef(c.oid, true), "
6295 "c.reloptions AS reloptions, "
6296 "NULL AS checkoption "
6297 "FROM pg_catalog.pg_class c "
6298 "LEFT JOIN pg_catalog.pg_namespace n "
6299 "ON c.relnamespace = n.oid WHERE c.oid = %u",
6338 case RELKIND_MATVIEW:
6355 if (reloptions != NULL && strlen(reloptions) > 2)
6372 if (
buf->len > 0 &&
buf->data[
buf->len - 1] ==
';')
6373 buf->data[--(
buf->len)] =
'\0';
6376 if (checkoption && checkoption[0] !=
'\0')
6383 if (
buf->len > 0 &&
buf->data[
buf->len - 1] !=
'\n')
6413 if (!obj || obj[0] ==
'\0')
6416 c = obj + strlen(obj) - 1;
6429 while (
c > obj && isascii((
unsigned char) *
c) && isspace((
unsigned char) *
c))
6433 if (
c == obj || !isascii((
unsigned char) *
c) || !isdigit((
unsigned char) *
c))
6437 while (
c > obj && isascii((
unsigned char) *
c) && isdigit((
unsigned char) *
c))
6442 if (
c == obj || !isascii((
unsigned char) *
c) ||
6443 !(isspace((
unsigned char) *
c) || *
c ==
')'))
6469 const char *lines =
buf->data;
6471 while (*lines !=
'\0')
6475 lines = strchr(lines,
'\n');
6498 bool in_header = is_func;
6501 while (*lines !=
'\0')
6506 (strncmp(lines,
"AS ", 3) == 0 ||
6507 strncmp(lines,
"BEGIN ", 6) == 0 ||
6508 strncmp(lines,
"RETURN ", 7) == 0))
6516 eol = strchr(lines,
'\n');
void expand_tilde(char **filename)
PGresult * PSQLexec(const char *query)
volatile sig_atomic_t sigint_interrupt_enabled
char * get_conninfo_value(const char *keyword)
sigjmp_buf sigint_interrupt_jmp
int PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout, int min_rows)
void SetShellResultVariables(int wait_result)
void NoticeProcessor(void *arg, const char *message)
void clean_extended_state(void)
bool standard_strings(void)
bool setQFout(const char *fname)
bool recognized_connection_string(const char *connstr)
bool do_copy(const char *args)
static Datum values[MAXATTR]
#define ngettext(s, p, n)
void ResetCancelConn(void)
static backslashResult exec_command_startpipeline(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_endif(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static backslashResult exec_command_getresults(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_copyright(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_errverbose(PsqlScanState scan_state, bool active_branch)
int process_file(char *filename, bool use_relative_path)
static backslashResult exec_command_print(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static bool get_create_object_cmd(EditableObjectType obj_type, Oid oid, PQExpBuffer buf)
static backslashResult exec_command_html(PsqlScanState scan_state, bool active_branch)
static bool copy_previous_query(PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_g(PsqlScanState scan_state, bool active_branch, const char *cmd)
static char * pset_value_string(const char *param, printQueryOpt *popt)
static backslashResult exec_command_T(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_gdesc(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_help(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_close_prepared(PsqlScanState scan_state, bool active_branch, const char *cmd)
static void discard_query_text(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static bool set_unicode_line_style(const char *value, size_t vallen, unicode_linestyle *linestyle)
void restorePsetInfo(printQueryOpt *popt, printQueryOpt *save)
static backslashResult exec_command_a(PsqlScanState scan_state, bool active_branch)
static void ignore_boolean_expression(PsqlScanState scan_state)
static bool do_watch(PQExpBuffer query_buf, double sleep, int iter, int min_rows)
static backslashResult exec_command_flushrequest(PsqlScanState scan_state, bool active_branch)
printQueryOpt * savePsetInfo(const printQueryOpt *popt)
static backslashResult exec_command_bind(PsqlScanState scan_state, bool active_branch)
static const char * _unicode_linestyle2string(int linestyle)
static PQExpBuffer gather_boolean_expression(PsqlScanState scan_state)
static backslashResult exec_command_password(PsqlScanState scan_state, bool active_branch)
static bool is_true_boolean_expression(PsqlScanState scan_state, const char *name)
static backslashResult exec_command_bind_named(PsqlScanState scan_state, bool active_branch, const char *cmd)
static bool do_edit(const char *filename_arg, PQExpBuffer query_buf, int lineno, bool discard_on_quit, bool *edited)
static backslashResult exec_command_x(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_if(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static char * pset_quoted_string(const char *str)
static backslashResult exec_command_elif(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static bool param_is_newly_set(const char *old_val, const char *new_val)
static void ignore_slash_whole_line(PsqlScanState scan_state)
static backslashResult exec_command_f(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_reset(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf)
static backslashResult exec_command_out(PsqlScanState scan_state, bool active_branch)
static bool do_connect(enum trivalue reuse_previous_specification, char *dbname, char *user, char *host, char *port)
static bool lookup_object_oid(EditableObjectType obj_type, const char *desc, Oid *obj_oid)
static backslashResult exec_command_echo(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
static const char * pset_bool_string(bool val)
static int count_lines_in_buf(PQExpBuffer buf)
static bool echo_hidden_command(const char *query)
static void save_query_text_state(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static backslashResult exec_command_shell_escape(PsqlScanState scan_state, bool active_branch)
bool do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
static backslashResult exec_command_cd(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_gset(PsqlScanState scan_state, bool active_branch)
static void printSSLInfo(void)
static backslashResult exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, bool is_func)
static backslashResult exec_command_unset(PsqlScanState scan_state, bool active_branch, const char *cmd)
static void ignore_slash_filepipe(PsqlScanState scan_state)
static backslashResult exec_command_set(PsqlScanState scan_state, bool active_branch)
static bool printPsetInfo(const char *param, printQueryOpt *popt)
static const char * _align2string(enum printFormat in)
static char * read_connect_arg(PsqlScanState scan_state)
static char * restrict_key
static backslashResult exec_command_s(PsqlScanState scan_state, bool active_branch)
backslashResult HandleSlashCmds(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_prompt(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_watch(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_include(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_list(PsqlScanState scan_state, bool active_branch, const char *cmd)
static bool editFile(const char *fname, int lineno)
static backslashResult exec_command_sendpipeline(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_timing(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_restrict(PsqlScanState scan_state, bool active_branch, const char *cmd)
static bool exec_command_dfo(PsqlScanState scan_state, const char *cmd, const char *pattern, bool show_verbose, bool show_system)
void UnsyncVariables(void)
static backslashResult exec_command_unrestrict(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_endpipeline(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_C(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_encoding(PsqlScanState scan_state, bool active_branch)
static void wait_until_connected(PGconn *conn)
static backslashResult exec_command_edit(PsqlScanState scan_state, bool active_branch, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_else(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf)
static backslashResult exec_command_conninfo(PsqlScanState scan_state, bool active_branch)
static bool do_shell(const char *command)
static backslashResult exec_command_copy(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_slash_command_help(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_parse(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_crosstabview(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_pset(PsqlScanState scan_state, bool active_branch)
static void ignore_slash_options(PsqlScanState scan_state)
static backslashResult exec_command_flush(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_t(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command(const char *cmd, PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
void connection_warnings(bool in_startup)
static backslashResult exec_command_write(PsqlScanState scan_state, bool active_branch, const char *cmd, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static backslashResult exec_command_syncpipeline(PsqlScanState scan_state, bool active_branch)
static void minimal_error_message(PGresult *res)
static backslashResult exec_command_sf_sv(PsqlScanState scan_state, bool active_branch, const char *cmd, bool is_func)
static bool is_branching_command(const char *cmd)
static backslashResult exec_command_connect(PsqlScanState scan_state, bool active_branch)
static void print_with_linenumbers(FILE *output, char *lines, bool is_func)
static int strip_lineno_from_objdesc(char *obj)
static backslashResult exec_command_gexec(PsqlScanState scan_state, bool active_branch)
static backslashResult exec_command_z(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_lo(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_getenv(PsqlScanState scan_state, bool active_branch, const char *cmd)
static backslashResult exec_command_quit(PsqlScanState scan_state, bool active_branch)
static backslashResult process_command_g_options(char *first_option, PsqlScanState scan_state, bool active_branch, const char *cmd)
static void printGSSInfo(void)
static char * prompt_for_password(const char *username, bool *canceled)
static backslashResult exec_command_setenv(PsqlScanState scan_state, bool active_branch, const char *cmd)
enum _backslashResult backslashResult
void conditional_stack_set_paren_depth(ConditionalStack cstack, int depth)
ifState conditional_stack_peek(ConditionalStack cstack)
void conditional_stack_push(ConditionalStack cstack, ifState new_state)
bool conditional_stack_pop(ConditionalStack cstack)
void conditional_stack_set_query_len(ConditionalStack cstack, int len)
int conditional_stack_get_query_len(ConditionalStack cstack)
bool conditional_active(ConditionalStack cstack)
int conditional_stack_get_paren_depth(ConditionalStack cstack)
bool conditional_stack_poke(ConditionalStack cstack, ifState new_state)
#define fprintf(file, fmt, msg)
bool listUserMappings(const char *pattern, bool verbose)
bool listTSConfigs(const char *pattern, bool verbose)
bool describeRoles(const char *pattern, bool verbose, bool showSystem)
bool listOpFamilyFunctions(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool listPublications(const char *pattern)
bool listTSParsers(const char *pattern, bool verbose)
bool listExtensionContents(const char *pattern)
bool describeAggregates(const char *pattern, bool verbose, bool showSystem)
bool listForeignDataWrappers(const char *pattern, bool verbose)
bool listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
bool describeSubscriptions(const char *pattern, bool verbose)
bool describeRoleGrants(const char *pattern, bool showSystem)
bool listExtendedStats(const char *pattern)
bool describeTypes(const char *pattern, bool verbose, bool showSystem)
bool listOperatorFamilies(const char *access_method_pattern, const char *type_pattern, bool verbose)
bool listForeignServers(const char *pattern, bool verbose)
bool describeTableDetails(const char *pattern, bool verbose, bool showSystem)
bool listDomains(const char *pattern, bool verbose, bool showSystem)
bool listTSDictionaries(const char *pattern, bool verbose)
bool listDbRoleSettings(const char *pattern, const char *pattern2)
bool describeFunctions(const char *functypes, const char *func_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
bool listCollations(const char *pattern, bool verbose, bool showSystem)
bool listSchemas(const char *pattern, bool verbose, bool showSystem)
bool listExtensions(const char *pattern)
bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
bool listTSTemplates(const char *pattern, bool verbose)
bool describeTablespaces(const char *pattern, bool verbose)
bool listCasts(const char *pattern, bool verbose)
bool listOpFamilyOperators(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool describeOperators(const char *oper_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
bool listOperatorClasses(const char *access_method_pattern, const char *type_pattern, bool verbose)
bool listForeignTables(const char *pattern, bool verbose)
bool describeConfigurationParameters(const char *pattern, bool verbose, bool showSystem)
bool listEventTriggers(const char *pattern, bool verbose)
bool listDefaultACLs(const char *pattern)
bool listAllDbs(const char *pattern, bool verbose)
bool listConversions(const char *pattern, bool verbose, bool showSystem)
bool permissionsList(const char *pattern, bool showSystem)
bool describeAccessMethods(const char *pattern, bool verbose)
bool listLargeObjects(bool verbose)
bool listLanguages(const char *pattern, bool verbose, bool showSystem)
bool describePublications(const char *pattern)
bool objectDescription(const char *pattern, bool showSystem)
int errmsg(const char *fmt,...)
PGresult * PQchangePassword(PGconn *conn, const char *user, const char *passwd)
int PQserverVersion(const PGconn *conn)
char * PQoptions(const PGconn *conn)
char * PQdb(const PGconn *conn)
int PQfullProtocolVersion(const PGconn *conn)
char * PQport(const PGconn *conn)
char * PQhost(const PGconn *conn)
int PQconnectionUsedPassword(const PGconn *conn)
PQconninfoOption * PQconninfo(PGconn *conn)
PostgresPollingStatusType PQconnectPoll(PGconn *conn)
void PQconninfoFree(PQconninfoOption *connOptions)
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
int PQconnectionNeedsPassword(const PGconn *conn)
int PQconnectionUsedGSSAPI(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
int PQclientEncoding(const PGconn *conn)
PGconn * PQconnectStartParams(const char *const *keywords, const char *const *values, int expand_dbname)
void PQfinish(PGconn *conn)
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
char * PQhostaddr(const PGconn *conn)
int PQbackendPID(const PGconn *conn)
PQconninfoOption * PQconndefaults(void)
char * PQuser(const PGconn *conn)
PGpipelineStatus PQpipelineStatus(const PGconn *conn)
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
char * PQerrorMessage(const PGconn *conn)
int PQsocket(const PGconn *conn)
int PQsetClientEncoding(PGconn *conn, const char *encoding)
void PQfreemem(void *ptr)
char * PQresultVerboseErrorMessage(const PGresult *res, PGVerbosity verbosity, PGContextVisibility show_context)
PGresult * PQexec(PGconn *conn, const char *query)
int PQsocketPoll(int sock, int forRead, int forWrite, pg_usec_time_t end_time)
pg_usec_time_t PQgetCurrentTimeUSec(void)
int PQgssEncInUse(PGconn *conn)
const char * PQsslAttribute(PGconn *conn, const char *attribute_name)
int PQsslInUse(PGconn *conn)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
void * pg_realloc(void *ptr, size_t size)
#define pg_realloc_array(pointer, type, count)
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
void printTableCleanup(printTableContent *const content)
void restore_sigpipe_trap(void)
const printTextFormat * get_line_style(const printTableOpt *opt)
FILE * PageOutput(int lines, const printTableOpt *topt)
void refresh_utf8format(const printTableOpt *opt)
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
const printTextFormat pg_asciiformat
void ClosePager(FILE *pagerpipe)
const printTextFormat pg_asciiformat_old
void disable_sigpipe_trap(void)
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
printTextFormat pg_utf8format
volatile sig_atomic_t cancel_pressed
@ PRINT_XHEADER_EXACT_WIDTH
@ UNICODE_LINESTYLE_SINGLE
@ UNICODE_LINESTYLE_DOUBLE
Assert(PointerIsAligned(start, uint64))
void helpVariables(unsigned short int pager)
void helpSQL(const char *topic, unsigned short int pager)
void slashUsage(unsigned short int pager)
void print_copyright(void)
static const JsonPathKeyword keywords[]
bool do_lo_export(const char *loid_arg, const char *filename_arg)
bool do_lo_import(const char *filename_arg, const char *comment_arg)
bool do_lo_unlink(const char *loid_arg)
#define PQresultErrorField
void pg_logging_config(int new_flags)
#define pg_log_error(...)
#define pg_log_error_hint(...)
#define PG_LOG_FLAG_TERSE
int MainLoop(FILE *source)
char * pstrdup(const char *in)
void pfree(void *pointer)
static int server_version
#define pg_encoding_to_char
#define pg_log_warning(...)
void join_path_components(char *ret_path, const char *head, const char *tail)
#define is_absolute_path(filename)
int pg_strcasecmp(const char *s1, const char *s2)
void get_parent_directory(char *path)
void canonicalize_path_enc(char *path, int encoding)
bool has_drive_prefix(const char *path)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
#define PG_DIAG_MESSAGE_PRIMARY
static bool is_unixsock_path(const char *path)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PQExpBuffer createPQExpBuffer(void)
void initPQExpBuffer(PQExpBuffer str)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void destroyPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
static int fd(const char *x, int i)
char * psprintf(const char *fmt,...)
void psql_scan_reset(PsqlScanState state)
void psql_scan_slash_command_end(PsqlScanState state)
void psql_scan_set_paren_depth(PsqlScanState state, int depth)
char * psql_scan_slash_option(PsqlScanState state, enum slash_option_type type, char *quote, bool semicolon)
int psql_scan_get_paren_depth(PsqlScanState state)
char * psql_scan_slash_command(PsqlScanState state)
static int before(chr x, chr y)
#define relpath(rlocator, forknum)
#define DEFAULT_EDITOR_LINENUMBER_ARG
@ PSQL_ECHO_HIDDEN_NOEXEC
@ PSQL_SEND_PIPELINE_SYNC
@ PSQL_SEND_FLUSH_REQUEST
@ PSQL_SEND_START_PIPELINE_MODE
@ PSQL_SEND_EXTENDED_QUERY_PARAMS
@ PSQL_SEND_EXTENDED_PARSE
@ PSQL_SEND_END_PIPELINE_MODE
@ PSQL_SEND_EXTENDED_CLOSE
@ PSQL_SEND_EXTENDED_QUERY_PREPARED
void pg_usleep(long microsec)
char * simple_prompt_extended(const char *prompt, bool echo, PromptInterruptContext *prompt_ctx)
int strtoint(const char *restrict str, char **restrict endptr, int base)
const char * fmtId(const char *rawid)
void setFmtEncoding(int encoding)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)
bool appendReloptionsArray(PQExpBuffer buffer, const char *reloptions, const char *prefix, int encoding, bool std_strings)
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
volatile sig_atomic_t * enabled
PGresult * last_error_result
enum trivalue getPassword
PGContextVisibility show_context
PSQL_ECHO_HIDDEN echo_hidden
printQueryOpt * gsavepopt
const bool * translate_columns
unsigned short int expanded
unicode_linestyle unicode_border_linestyle
struct separator fieldSep
int expanded_header_exact_width
struct separator recordSep
printXheaderWidthType expanded_header_width_type
const printTextFormat * line_style
unsigned short int border
unicode_linestyle unicode_header_linestyle
unicode_linestyle unicode_column_linestyle
int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue)
static void usage(const char *progname)
void PrintVariables(VariableSpace space)
void PsqlVarEnumError(const char *name, const char *value, const char *suggestions)
bool ParseVariableBool(const char *value, const char *name, bool *result)
bool ParseVariableNum(const char *value, const char *name, int *result)
bool SetVariable(VariableSpace space, const char *name, const char *value)
char * wait_result_to_str(int exitstatus)