psql tab auto-complete for CREATE PUBLICATION

Started by Peter Smithover 4 years ago4 messages
#1Peter Smith
smithpb2250@gmail.com
1 attachment(s)

I found that the psql tab auto-complete was not working for some cases
of CREATE PUBLICATION [1]https://www.postgresql.org/docs/devel/sql-createpublication.html.

CREATE PUBLICATION name
[ FOR TABLE [ ONLY ] table_name [ * ] [, ...]
| FOR ALL TABLES ]
[ WITH ( publication_parameter [= value] [, ... ] ) ]

~~~

For example, the following scenarios did not work as I was expecting:

"create publication mypub for all tables " TAB --> expected complete
with "WITH ("

"create publication mypub for all ta" TAB --> expected complete with "TABLES"

"create publication mypub for all tables w" TAB --> expected complete
with "WITH ("

"create publication mypub for table mytable " TAB --> expected
complete with "WITH ("

~~~

PSA a small patch which seems to improve at least for those
aforementioned cases.

Now results are:

"create publication mypub for all tables " TAB --> "create publication
mypub for all tables WITH ( "

"create publication mypub for all ta" TAB --> "create publication
mypub for all tables "

"create publication mypub for all tables w" TAB --> "create
publication mypub for all tables with ( "

"create publication mypub for table mytable " TAB --> "create
publication mypub for table mytable WITH ( "

------
[1]: https://www.postgresql.org/docs/devel/sql-createpublication.html

Kind Regards,
Peter Smith
Fujitsu Australia

Attachments:

v1-0001-more-auto-complete-for-CREATE-PUBLICATION.patchapplication/octet-stream; name=v1-0001-more-auto-complete-for-CREATE-PUBLICATION.patchDownload
From b3ae83b75ff2841df9b89208a5f003a143687a0f Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.b.smith@fujitsu.com>
Date: Fri, 9 Jul 2021 16:27:21 +1000
Subject: [PATCH v1] more auto-complete for CREATE PUBLICATION

---
 src/bin/psql/tab-complete.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 0ebd5aa..86a8120 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2637,8 +2637,13 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH("FOR TABLE", "FOR ALL TABLES", "WITH (");
 	else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR"))
 		COMPLETE_WITH("TABLE", "ALL TABLES");
-	/* Complete "CREATE PUBLICATION <name> FOR TABLE <table>, ..." */
-	else if (HeadMatches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLE"))
+	else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "ALL"))
+		COMPLETE_WITH("TABLES");
+	else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "ALL", "TABLES")
+		|| Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLE", MatchAny))
+		COMPLETE_WITH("WITH (");
+	/* Complete "CREATE PUBLICATION <name> FOR TABLE" with "<table>, ..." */
+	else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLE"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
 	/* Complete "CREATE PUBLICATION <name> [...] WITH" */
 	else if (HeadMatches("CREATE", "PUBLICATION") && TailMatches("WITH", "("))
-- 
1.8.3.1

#2vignesh C
vignesh21@gmail.com
In reply to: Peter Smith (#1)
Re: psql tab auto-complete for CREATE PUBLICATION

On Fri, Jul 9, 2021 at 1:06 PM Peter Smith <smithpb2250@gmail.com> wrote:

I found that the psql tab auto-complete was not working for some cases
of CREATE PUBLICATION [1].

CREATE PUBLICATION name
[ FOR TABLE [ ONLY ] table_name [ * ] [, ...]
| FOR ALL TABLES ]
[ WITH ( publication_parameter [= value] [, ... ] ) ]

~~~

For example, the following scenarios did not work as I was expecting:

"create publication mypub for all tables " TAB --> expected complete
with "WITH ("

"create publication mypub for all ta" TAB --> expected complete with "TABLES"

"create publication mypub for all tables w" TAB --> expected complete
with "WITH ("

"create publication mypub for table mytable " TAB --> expected
complete with "WITH ("

~~~

PSA a small patch which seems to improve at least for those
aforementioned cases.

Now results are:

"create publication mypub for all tables " TAB --> "create publication
mypub for all tables WITH ( "

"create publication mypub for all ta" TAB --> "create publication
mypub for all tables "

"create publication mypub for all tables w" TAB --> "create
publication mypub for all tables with ( "

"create publication mypub for table mytable " TAB --> "create
publication mypub for table mytable WITH ( "

Thanks for the patch, the changes look good to me.

Regards,
Vignesh

#3Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: vignesh C (#2)
Re: psql tab auto-complete for CREATE PUBLICATION

On 2021/07/17 2:19, vignesh C wrote:

Thanks for the patch, the changes look good to me.

The patch looks good to me, too. Pushed. Thanks!

Regards,

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

#4Peter Smith
smithpb2250@gmail.com
In reply to: Fujii Masao (#3)
Re: psql tab auto-complete for CREATE PUBLICATION

On Wed, Sep 1, 2021 at 11:04 PM Fujii Masao <masao.fujii@oss.nttdata.com> wrote:

On 2021/07/17 2:19, vignesh C wrote:

Thanks for the patch, the changes look good to me.

The patch looks good to me, too. Pushed. Thanks!

Thanks for pushing!

------
Kind Regards,
Peter Smith.
Fujitsu Australia