Commit 8eb6407a authored by Tom Lane's avatar Tom Lane

Add psql \ev and \sv commands for editing and showing view definitions.

These are basically just like the \ef and \sf commands for functions.

Petr Korobeinikov, reviewed by Jeevan Chalke, some changes by me
parent 1bc90f7a
......@@ -1650,6 +1650,32 @@ Tue Oct 26 21:40:57 CEST 1999
</varlistentry>
<varlistentry>
<term><literal>\ev <optional> <replaceable class="parameter">view_name</> <optional> <replaceable class="parameter">line_number</> </optional> </optional> </literal></term>
<listitem>
<para>
This command fetches and edits the definition of the named view,
in the form of a <command>CREATE OR REPLACE VIEW</> command.
Editing is done in the same way as for <literal>\edit</>.
After the editor exits, the updated command waits in the query buffer;
type semicolon or <literal>\g</> to send it, or <literal>\r</>
to cancel.
</para>
<para>
If no view is specified, a blank <command>CREATE VIEW</>
template is presented for editing.
</para>
<para>
If a line number is specified, <application>psql</application> will
position the cursor on the specified line of the view definition.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>\encoding [ <replaceable class="parameter">encoding</replaceable> ]</literal></term>
......@@ -2521,6 +2547,25 @@ testdb=&gt; <userinput>\setenv LESS -imx4F</userinput>
</varlistentry>
<varlistentry>
<term><literal>\sv[+] <replaceable class="parameter">view_name</> </literal></term>
<listitem>
<para>
This command fetches and shows the definition of the named view,
in the form of a <command>CREATE OR REPLACE VIEW</> command.
The definition is printed to the current query output channel,
as set by <command>\o</command>.
</para>
<para>
If <literal>+</literal> is appended to the command name, then the
output lines are numbered from 1.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>\t</literal></term>
<listitem>
......@@ -3554,9 +3599,10 @@ $endif
<listitem>
<para>
Editor used by the <command>\e</command> and
<command>\ef</command> commands. The variables are examined in
the order listed; the first that is set is used.
Editor used by the <command>\e</command>, <command>\ef</command>,
and <command>\ev</command> commands.
These variables are examined in the order listed;
the first that is set is used.
</para>
<para>
......@@ -3571,7 +3617,8 @@ $endif
<listitem>
<para>
When <command>\e</command> or <command>\ef</command> is used
When <command>\e</command>, <command>\ef</command>, or
<command>\ev</command> is used
with a line number argument, this variable specifies the
command-line argument used to pass the starting line number to
the user's editor. For editors such as <productname>Emacs</> or
......
This diff is collapsed.
......@@ -181,6 +181,7 @@ slashUsage(unsigned short int pager)
fprintf(output, _("Query Buffer\n"));
fprintf(output, _(" \\e [FILE] [LINE] edit the query buffer (or file) with external editor\n"));
fprintf(output, _(" \\ef [FUNCNAME [LINE]] edit function definition with external editor\n"));
fprintf(output, _(" \\ev [VIEWNAME [LINE]] edit view definition with external editor\n"));
fprintf(output, _(" \\p show the contents of the query buffer\n"));
fprintf(output, _(" \\r reset (clear) the query buffer\n"));
#ifdef USE_READLINE
......@@ -237,7 +238,8 @@ slashUsage(unsigned short int pager)
fprintf(output, _(" \\dx[+] [PATTERN] list extensions\n"));
fprintf(output, _(" \\dy [PATTERN] list event triggers\n"));
fprintf(output, _(" \\l[+] [PATTERN] list databases\n"));
fprintf(output, _(" \\sf[+] FUNCNAME show a function's definition\n"));
fprintf(output, _(" \\sf[+] FUNCNAME show a function's definition\n"));
fprintf(output, _(" \\sv[+] VIEWNAME show a view's definition\n"));
fprintf(output, _(" \\z [PATTERN] same as \\dp\n"));
fprintf(output, "\n");
......@@ -388,7 +390,7 @@ helpVariables(unsigned short int pager)
fprintf(output, _(" PGPASSWORD connection password (not recommended)\n"));
fprintf(output, _(" PGPASSFILE password file name\n"));
fprintf(output, _(" PSQL_EDITOR, EDITOR, VISUAL\n"
" editor used by the \\e and \\ef commands\n"));
" editor used by the \\e, \\ef, and \\ev commands\n"));
fprintf(output, _(" PSQL_EDITOR_LINENUMBER_ARG\n"
" how to specify a line number when invoking the editor\n"));
fprintf(output, _(" PSQL_HISTORY alternative location for the command history file\n"));
......
......@@ -900,11 +900,11 @@ psql_completion(const char *text, int start, int end)
"\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\des", "\\det", "\\deu", "\\dew", "\\df",
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
"\\dn", "\\do", "\\dp", "\\drds", "\\ds", "\\dS", "\\dt", "\\dT", "\\dv", "\\du", "\\dx",
"\\e", "\\echo", "\\ef", "\\encoding",
"\\e", "\\echo", "\\ef", "\\encoding", "\\ev",
"\\f", "\\g", "\\gset", "\\h", "\\help", "\\H", "\\i", "\\ir", "\\l",
"\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink",
"\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r",
"\\set", "\\sf", "\\t", "\\T",
"\\set", "\\sf", "\\sv", "\\t", "\\T",
"\\timing", "\\unset", "\\x", "\\w", "\\watch", "\\z", "\\!", NULL
};
......@@ -2591,7 +2591,7 @@ psql_completion(const char *text, int start, int end)
"NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NOINHERIT",
"NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "PASSWORD",
"REPLICATION", "ROLE", "SUPERUSER", "SYSID", "UNENCRYPTED",
"VALID UNTIL", "WITH", NULL};
"VALID UNTIL", "WITH", NULL};
COMPLETE_WITH_LIST(list_CREATEROLE);
}
......@@ -2610,7 +2610,7 @@ psql_completion(const char *text, int start, int end)
"NOCREATEDB", "NOCREATEROLE", "NOCREATEUSER", "NOINHERIT",
"NOLOGIN", "NOREPLICATION", "NOSUPERUSER", "PASSWORD",
"REPLICATION", "ROLE", "SUPERUSER", "SYSID", "UNENCRYPTED",
"VALID UNTIL", NULL};
"VALID UNTIL", NULL};
COMPLETE_WITH_LIST(list_CREATEROLE_WITH);
}
......@@ -3798,6 +3798,8 @@ psql_completion(const char *text, int start, int end)
else if (strcmp(prev_wd, "\\ef") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
else if (strcmp(prev_wd, "\\ev") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL);
else if (strcmp(prev_wd, "\\encoding") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_encodings);
......@@ -3912,6 +3914,8 @@ psql_completion(const char *text, int start, int end)
}
else if (strcmp(prev_wd, "\\sf") == 0 || strcmp(prev_wd, "\\sf+") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL);
else if (strcmp(prev_wd, "\\sv") == 0 || strcmp(prev_wd, "\\sv+") == 0)
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_views, NULL);
else if (strcmp(prev_wd, "\\cd") == 0 ||
strcmp(prev_wd, "\\e") == 0 || strcmp(prev_wd, "\\edit") == 0 ||
strcmp(prev_wd, "\\g") == 0 ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment