Tab completion for CREATE SEQUENCE

Started by Vik Fearingover 10 years ago7 messages
#1Vik Fearing
vik@2ndquadrant.fr
1 attachment(s)

While reviewing the seqam patches, I noticed that psql has tab
completion for ALTER SEQUENCE, but not for CREATE SEQUENCE.

The attached trivial patch fixes that.
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

Attachments:

create_seq_tab_complete.v01.patchtext/x-patch; name=create_seq_tab_complete.v01.patchDownload
*** a/src/bin/psql/tab-complete.c
--- b/src/bin/psql/tab-complete.c
***************
*** 2445,2450 **** psql_completion(const char *text, int start, int end)
--- 2445,2471 ----
  			 pg_strcasecmp(prev_wd, "TO") == 0)
  		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
  
+ 	/* CREATE SEQUENCE <name> */
+ 	else if (pg_strcasecmp(prev3_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev2_wd, "SEQUENCE") == 0)
+ 	{
+ 		static const char *const list_CREATESEQUENCE[] =
+ 		{"INCREMENT", "MINVALUE", "MAXVALUE", "RESTART", "NO", "CACHE", "CYCLE",
+ 		"SET SCHEMA", "OWNED BY", "OWNER TO", "RENAME TO", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_CREATESEQUENCE);
+ 	}
+ 	/* CREATE SEQUENCE <name> NO */
+ 	else if (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
+ 			 pg_strcasecmp(prev3_wd, "SEQUENCE") == 0 &&
+ 			 pg_strcasecmp(prev_wd, "NO") == 0)
+ 	{
+ 		static const char *const list_CREATESEQUENCE2[] =
+ 		{"MINVALUE", "MAXVALUE", "CYCLE", NULL};
+ 
+ 		COMPLETE_WITH_LIST(list_CREATESEQUENCE2);
+ 	}
+ 
  /* CREATE SERVER <name> */
  	else if (pg_strcasecmp(prev3_wd, "CREATE") == 0 &&
  			 pg_strcasecmp(prev2_wd, "SERVER") == 0)
#2Brendan Jurd
direvus@gmail.com
In reply to: Vik Fearing (#1)
Re: Tab completion for CREATE SEQUENCE

On Tue, 16 Jun 2015 at 00:52 Vik Fearing <vik@2ndquadrant.fr> wrote:

While reviewing the seqam patches, I noticed that psql has tab
completion for ALTER SEQUENCE, but not for CREATE SEQUENCE.

The attached trivial patch fixes that.

Hi Vik,

I'm doing an initial review of this patch.

It applies cleanly, although for some reason the patch seems to introduce
carriage returns in the line endings. `patch` warned about those and then
very sensibly ignored them. Everything compiled fine after applying.

The new code's style is not quite in accordance with the surrounds. I
think that the comments introducing each section should be de-indented to
the first column.

"RESTART", "SET SCHEMA", "OWNER TO", and "RENAME TO" are not valid
completions for CREATE SEQUENCE. It looks like these have been blindly
copy-pasted from ALTER SEQUENCE. Likewise, the valid completion "START
[WITH]" is missing.

"CREATE TEMP[ORARY] SEQUENCE" is not supported, and I think it probably
should be. I think that the patch could be improved with support for the
TEMP form fairly easily.

Apart from the above points, the new completions worked as advertised.

Docs: none needed.

Tests: we don't currently have any test coverage for psql tab completion.

I'm marking this "Waiting on Author". Once the problems have been
corrected, it should be ready for a committer.

Cheers,
BJ

#3Andres Freund
andres@anarazel.de
In reply to: Brendan Jurd (#2)
Re: Tab completion for CREATE SEQUENCE

On 2015-06-19 06:41:19 +0000, Brendan Jurd wrote:

I'm marking this "Waiting on Author". Once the problems have been
corrected, it should be ready for a committer.

Vik, are you going to update the patch?

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Michael Paquier
michael.paquier@gmail.com
In reply to: Andres Freund (#3)
1 attachment(s)
Re: Tab completion for CREATE SEQUENCE

On Tue, Jul 7, 2015 at 9:14 PM, Andres Freund <andres@anarazel.de> wrote:

On 2015-06-19 06:41:19 +0000, Brendan Jurd wrote:

I'm marking this "Waiting on Author". Once the problems have been
corrected, it should be ready for a committer.

Vik, are you going to update the patch?

Seeing no activity on this thread and as it would be a waste not to do
it, I completed the patch as attached. The following things are done:
- Fixed code indentation
- Removal of "RESTART", "SET SCHEMA", "OWNER TO", and "RENAME TO" in
CREATE SEQUENCE
- Added "START WITH".
- Added TEMP/TEMPORARY in the set of keywords tracked.
I am switching at the same time this patch as "Ready for committer".
Regards,
--
Michael

Attachments:

20150803_createseq_tab_compl.patchapplication/x-patch; name=20150803_createseq_tab_compl.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index ece0515..0748284 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2467,6 +2467,35 @@ psql_completion(const char *text, int start, int end)
 			 pg_strcasecmp(prev_wd, "TO") == 0)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
 
+/* CREATE TEMP/TEMPORARY SEQUENCE <name> */
+	else if ((pg_strcasecmp(prev3_wd, "CREATE") == 0 &&
+			  pg_strcasecmp(prev2_wd, "SEQUENCE") == 0) ||
+			 (pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
+			  (pg_strcasecmp(prev3_wd, "TEMP") == 0 ||
+			   pg_strcasecmp(prev3_wd, "TEMPORARY") == 0) &&
+			  pg_strcasecmp(prev2_wd, "SEQUENCE") == 0))
+	{
+		static const char *const list_CREATESEQUENCE[] =
+		{"INCREMENT BY", "MINVALUE", "MAXVALUE", "RESTART", "NO", "CACHE",
+		 "CYCLE", "OWNED BY", "START WITH", NULL};
+
+		COMPLETE_WITH_LIST(list_CREATESEQUENCE);
+	}
+/* CREATE TEMP/TEMPORARY SEQUENCE <name> NO */
+	else if ((pg_strcasecmp(prev4_wd, "CREATE") == 0 &&
+			  pg_strcasecmp(prev3_wd, "SEQUENCE") == 0) ||
+			 (pg_strcasecmp(prev5_wd, "CREATE") == 0 &&
+			  (pg_strcasecmp(prev4_wd, "TEMP") == 0 ||
+			   pg_strcasecmp(prev4_wd, "TEMPORARY") == 0) &&
+			  pg_strcasecmp(prev3_wd, "SEQUENCE") == 0) &&
+			 pg_strcasecmp(prev_wd, "NO") == 0)
+	{
+		static const char *const list_CREATESEQUENCE2[] =
+		{"MINVALUE", "MAXVALUE", "CYCLE", NULL};
+
+		COMPLETE_WITH_LIST(list_CREATESEQUENCE2);
+	}
+
 /* CREATE SERVER <name> */
 	else if (pg_strcasecmp(prev3_wd, "CREATE") == 0 &&
 			 pg_strcasecmp(prev2_wd, "SERVER") == 0)
#5Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#4)
Re: Tab completion for CREATE SEQUENCE

On Mon, Aug 3, 2015 at 2:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Tue, Jul 7, 2015 at 9:14 PM, Andres Freund <andres@anarazel.de> wrote:

On 2015-06-19 06:41:19 +0000, Brendan Jurd wrote:

I'm marking this "Waiting on Author". Once the problems have been
corrected, it should be ready for a committer.

Vik, are you going to update the patch?

Seeing no activity on this thread and as it would be a waste not to do
it, I completed the patch as attached. The following things are done:
- Fixed code indentation
- Removal of "RESTART", "SET SCHEMA", "OWNER TO", and "RENAME TO" in
CREATE SEQUENCE
- Added "START WITH".
- Added TEMP/TEMPORARY in the set of keywords tracked.
I am switching at the same time this patch as "Ready for committer".

You didn't remove RESTART, so I did that. And this needed some more
parentheses to make my compiler happy.

Committed with those changes.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Vik Fearing
vik@2ndquadrant.fr
In reply to: Robert Haas (#5)
Re: Tab completion for CREATE SEQUENCE

On 08/04/2015 06:30 PM, Robert Haas wrote:

On Mon, Aug 3, 2015 at 2:17 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Tue, Jul 7, 2015 at 9:14 PM, Andres Freund <andres@anarazel.de> wrote:

On 2015-06-19 06:41:19 +0000, Brendan Jurd wrote:

I'm marking this "Waiting on Author". Once the problems have been
corrected, it should be ready for a committer.

Vik, are you going to update the patch?

Seeing no activity on this thread and as it would be a waste not to do
it, I completed the patch as attached. The following things are done:
- Fixed code indentation
- Removal of "RESTART", "SET SCHEMA", "OWNER TO", and "RENAME TO" in
CREATE SEQUENCE
- Added "START WITH".
- Added TEMP/TEMPORARY in the set of keywords tracked.
I am switching at the same time this patch as "Ready for committer".

You didn't remove RESTART, so I did that. And this needed some more
parentheses to make my compiler happy.

Committed with those changes.

Thank you, Brendan, Michael, and Robert for taking care of this while I
was away.
--
Vik Fearing +33 6 46 75 15 36
http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Robert Haas
robertmhaas@gmail.com
In reply to: Vik Fearing (#6)
Re: Tab completion for CREATE SEQUENCE

On Wed, Aug 12, 2015 at 9:22 AM, Vik Fearing <vik@2ndquadrant.fr> wrote:

Thank you, Brendan, Michael, and Robert for taking care of this while I
was away.

Thanks for the patch!

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers