From: Shinya11.Kato@nttdata.com
To: pgsql-hackers@postgresql.org
Subject: [PATCH] Feature improvement for CLOSE, FETCH, MOVE tab completion
Date: Wed, 9 Dec 2020 03:57:55 +0000
Message-ID: <b0e4c5c53ef84c5395524f5056fc71f0@MP-MSGSS-MBX001.msg.nttdata.co.jp> (raw)
Hi!
I created a patch for improving CLOSE, FETCH, MOVE tab completion.
Specifically, I add CLOSE, FETCH, MOVE tab completion for completing a predefined cursors.
Regards,
Shinya Kato
Attachments:fix_tab_complete_close_fetch_move.patch (application/octet-stream, 3.6K) downloaddiff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.cindex 3a43c09bf6..6b5b326c58 100644--- a/src/bin/psql/tab-complete.c+++ b/src/bin/psql/tab-complete.c@@ -976,6 +976,9 @@ static const SchemaQuery Query_for_list_of_statistics = {
" and pg_catalog.pg_table_is_visible(c2.oid)"\
" and c2.relispartition = 'true'"
+#define Query_for_list_of_cursors \+" SELECT name FROM pg_cursors"\+
/*
* These object types were introduced later than our support cutoff of
* server version 7.4. We use the VersionedQuery infrastructure so that
@@ -2284,6 +2287,10 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures, NULL);
else if (Matches("CALL", MatchAny))
COMPLETE_WITH("(");
+/* CLOSE */+ else if (Matches("CLOSE"))+ COMPLETE_WITH_QUERY(Query_for_list_of_cursors+ " UNION ALL SELECT 'ALL'");
/* CLUSTER */
else if (Matches("CLUSTER"))
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_clusterables, "UNION SELECT 'VERBOSE'");
@@ -3166,26 +3173,44 @@ psql_completion(const char *text, int start, int end)
/* FETCH && MOVE */
/*
- * Complete FETCH with one of ABSOLUTE, BACKWARD, FORWARD, RELATIVE, ALL,- * NEXT, PRIOR, FIRST, LAST+ * Complete FETCH with a list of cursors and one of ABSOLUTE, BACKWARD, FORWARD, RELATIVE, ALL,+ * NEXT, PRIOR, FIRST, LAST, FROM, IN
*/
else if (Matches("FETCH|MOVE"))
- COMPLETE_WITH("ABSOLUTE", "BACKWARD", "FORWARD", "RELATIVE",- "ALL", "NEXT", "PRIOR", "FIRST", "LAST");-- /* Complete FETCH BACKWARD or FORWARD with one of ALL, FROM, IN */+ COMPLETE_WITH_QUERY(Query_for_list_of_cursors+ " UNION SELECT 'ABSOLUTE'"+ " UNION SELECT 'BACKWARD'"+ " UNION SELECT 'FORWARD'"+ " UNION SELECT 'RELATIVE'"+ " UNION SELECT 'ALL'"+ " UNION SELECT 'NEXT'"+ " UNION SELECT 'PRIOR'"+ " UNION SELECT 'FIRST'"+ " UNION SELECT 'LAST'"+ " UNION SELECT 'FROM'"+ " UNION SELECT 'IN'" + );++ /* Complete FETCH BACKWARD or FORWARD with a list of cursors and one of ALL, FROM, IN */
else if (Matches("FETCH|MOVE", "BACKWARD|FORWARD"))
- COMPLETE_WITH("ALL", "FROM", "IN");+ COMPLETE_WITH_QUERY(Query_for_list_of_cursors+ " UNION SELECT 'ALL'"+ " UNION SELECT 'FROM'"+ " UNION SELECT 'IN'"+ );- /*- * Complete FETCH <direction> with "FROM" or "IN". These are equivalent,- * but we may as well tab-complete both: perhaps some users prefer one- * variant or the other.- */+ /* Complete FETCH <direction> with a list of cursors and "FROM" or "IN" */
else if (Matches("FETCH|MOVE", "ABSOLUTE|BACKWARD|FORWARD|RELATIVE",
MatchAnyExcept("FROM|IN")) ||
Matches("FETCH|MOVE", "ALL|NEXT|PRIOR|FIRST|LAST"))
- COMPLETE_WITH("FROM", "IN");+ COMPLETE_WITH_QUERY(Query_for_list_of_cursors+ " UNION SELECT 'FROM'"+ " UNION SELECT 'IN'"+ );+ /* Complete FETCH <direction> FROM or IN with a list of cursors */+ else if (HeadMatches("FETCH|MOVE") &&+ TailMatches("FROM|IN"))+ COMPLETE_WITH_QUERY(Query_for_list_of_cursors);
/* FOREIGN DATA WRAPPER */
/* applies in ALTER/DROP FDW and in CREATE SERVER */
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: Shinya11.Kato@nttdata.com
Subject: Re: [PATCH] Feature improvement for CLOSE, FETCH, MOVE tab completion
In-Reply-To: <b0e4c5c53ef84c5395524f5056fc71f0@MP-MSGSS-MBX001.msg.nttdata.co.jp>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox