[PATCH] Feature improvement for TRUNCATE tab completion.

Started by miyake_koutaalmost 5 years ago4 messages
#1miyake_kouta
miyake_kouta@oss.nttdata.com
1 attachment(s)

Hi.

I created a patch which improves psql's TRUNCATE tab completion.
Current tab completion can complement only a table name to be truncated.
This patch enables psql to complement other keywords related to
TRUNCATE.

Regards.
Kota Miyake

Attachments:

truncate_tab_completion.patchtext/x-diff; name=truncate_tab_completion.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 1e1c315bae..ef9ef4cb25 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3799,7 +3799,20 @@ psql_completion(const char *text, int start, int end)
 
 /* TRUNCATE */
 	else if (Matches("TRUNCATE"))
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
+							" UNION SELECT 'TABLE'"
+							" UNION SELECT 'ONLY'");
+	else if (Matches("TRUNCATE", "TABLE"))
+		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
+							" UNION SELECT 'ONLY'");
+	else if (HeadMatches("TRUNCATE") && TailMatches("ONLY"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
+	else if (Matches("TRUNCATE", MatchAny) ||
+			Matches("TRUNCATE", "TABLE|ONLY", MatchAny) ||
+			Matches("TRUNCATE", "TABLE", "ONLY", MatchAny))
+		COMPLETE_WITH("RESTART IDENTITY", "CONTINUE IDENTITY", "CASCADE", "RESTRICT");
+	else if (HeadMatches("TRUNCATE") && TailMatches("IDENTITY"))
+		COMPLETE_WITH("CASCADE", "RESTRICT");
 
 /* UNLISTEN */
 	else if (Matches("UNLISTEN"))
#2Muhammad Usama
m.usama@gmail.com
In reply to: miyake_kouta (#1)
Re: [PATCH] Feature improvement for TRUNCATE tab completion.

The following review has been posted through the commitfest application:
make installcheck-world: not tested
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: not tested

Other than "Hunk #1 succeeded at 3832 (offset 33 lines)." message while applying the patch to
current master branch (commit 6a03369a71d4a7dc5b8d928aab775ddd28b72494) I found no issue with the patch.

The new status of this patch is: Ready for Committer

#3Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Muhammad Usama (#2)
Re: [PATCH] Feature improvement for TRUNCATE tab completion.

On 2021/02/23 1:44, Muhammad Usama wrote:

The following review has been posted through the commitfest application:
make installcheck-world: not tested
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: not tested

Other than "Hunk #1 succeeded at 3832 (offset 33 lines)." message while applying the patch to
current master branch (commit 6a03369a71d4a7dc5b8d928aab775ddd28b72494) I found no issue with the patch.

The new status of this patch is: Ready for Committer

OK, so barring any objection, I will commit this patch.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

#4Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Fujii Masao (#3)
Re: [PATCH] Feature improvement for TRUNCATE tab completion.

On 2021/02/24 12:59, Fujii Masao wrote:

On 2021/02/23 1:44, Muhammad Usama wrote:

The following review has been posted through the commitfest application:
make installcheck-world:  not tested
Implements feature:       tested, passed
Spec compliant:           tested, passed
Documentation:            not tested

Other than "Hunk #1 succeeded at 3832 (offset 33 lines)." message while applying the patch to
current master branch (commit 6a03369a71d4a7dc5b8d928aab775ddd28b72494) I found no issue with the patch.

The new status of this patch is: Ready for Committer

OK, so barring any objection, I will commit this patch.

Pushed. Thanks!

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION