psql_slash_n.patch
application/octet-stream
Filename: psql_slash_n.patch
Type: application/octet-stream
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/bin/psql/command.c | 35 | 0 |
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index c5ec981..e4a5310 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -868,6 +868,41 @@ exec_command(const char *cmd,
free(opt2);
}
+ /* \n -- shortcut for set search_path */
+ else if (strcmp(cmd, "n") == 0)
+ {
+ char *search_path;
+ char *opt;
+
+ PQExpBufferData buf;
+ PGresult *res;
+
+ opt = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false);
+ search_path = pg_strdup(opt ? opt : "");
+ free(opt);
+
+ while ((opt = psql_scan_slash_option(scan_state, OT_NORMAL, NULL, false)))
+ {
+ search_path = realloc(search_path, strlen(search_path) + strlen(opt) + 1);
+ if (!search_path)
+ {
+ psql_error("out of memory\n");
+ exit(EXIT_FAILURE);
+ }
+ strcat(search_path, opt);
+ free(opt);
+ }
+
+ initPQExpBuffer(&buf);
+ printfPQExpBuffer(&buf, "SET search_path = %s", search_path);
+ res = PSQLexec(buf.data, false);
+ termPQExpBuffer(&buf);
+ if (!res)
+ success = false;
+ else
+ PQclear(res);
+ free(search_path);
+ }
/* \o -- set query output */
else if (strcmp(cmd, "o") == 0 || strcmp(cmd, "out") == 0)