diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 09939fd..1c4af37 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -901,6 +901,41 @@ exec_command(const char *cmd,
 		free(opt2);
 	}
 
+        /* \ns -- shortcut for set search_path */
+        else if (strcmp(cmd, "ns") == 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)
