*** a/src/bin/psql/command.c --- b/src/bin/psql/command.c *************** *** 1355,1360 **** exec_command(const char *cmd, --- 1355,1398 ---- free(opt); } + /* \vt -- show sample of table */ + else if (strcmp(cmd, "vt") == 0) + { + char *relname; + char *ln; + + /* We don't do SQLID reduction on the pattern yet */ + relname = psql_scan_slash_option(scan_state, + OT_NORMAL, NULL, false); + + printfPQExpBuffer(query_buf, "SELECT * FROM %s", relname); + + /* try to get separate lineno arg */ + ln = psql_scan_slash_option(scan_state, + OT_NORMAL, NULL, true); + if (ln != NULL) + { + int lineno = atoi(ln); + + if (lineno < 1) + { + psql_error("invalid line number: %s\n", ln); + status = PSQL_CMD_ERROR; + } + else + appendPQExpBuffer(query_buf, " LIMIT %d", lineno); + + pfree(ln); + } + else + appendPQExpBuffer(query_buf, " LIMIT 10"); + + if (status != PSQL_CMD_ERROR) + success = SendQuery(query_buf->data); + + pfree(relname); + } + /* \w -- write query buffer to file */ else if (strcmp(cmd, "w") == 0 || strcmp(cmd, "write") == 0) { *************** *** 1430,1435 **** exec_command(const char *cmd, --- 1468,1474 ---- free(opt); } + /* \z -- list table rights (equivalent to \dp) */ else if (strcmp(cmd, "z") == 0) { *** a/src/bin/psql/tab-complete.c --- b/src/bin/psql/tab-complete.c *************** *** 869,875 **** psql_completion(char *text, int start, int end) "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink", "\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r", "\\set", "\\sf", "\\t", "\\T", ! "\\timing", "\\unset", "\\x", "\\w", "\\z", "\\!", NULL }; (void) end; /* not used */ --- 869,875 ---- "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink", "\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r", "\\set", "\\sf", "\\t", "\\T", ! "\\timing", "\\unset", "\\x", "\\vt", "\\w", "\\z", "\\!", NULL }; (void) end; /* not used */ *************** *** 3239,3244 **** psql_completion(char *text, int start, int end) --- 3239,3246 ---- completion_charp = "\\"; matches = completion_matches(text, complete_from_files); } + else if (strncmp(prev_wd, "\\vt", strlen("\\vt")) == 0) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL); /* * Finally, we look through the list of "things", such as TABLE, INDEX and