Add a tab-completion for "SELECT <sth> INTO" or "SELECT <sth> FROM" in psql

Started by C,C Hover 7 years ago2 messages
#1C,C H
a12321aabb@gmail.com
1 attachment(s)

Hi,

I use tab-completion in psql quite often and I find that I can't complete
"FROM" for SELECT query.

So I try to create a patch for it.

I download the source code from GitHub master branch and modify the file to
create the patch.

I compile the code and my code change works like follows,
--------------------------------------------------------------
postgres=# SELECT * <Tab Key><Tab Key>
FROM INTO
postgres=# SELECT *
--------------------------------------------------------------

This is my first patch contribution trial here, please correct me if there
is something wrong.

Thanks.

CCHsu

Attachments:

psql_select_from_completion.patchapplication/octet-stream; name=psql_select_from_completion.patchDownload
--- ./src/bin/psql/tab-complete.c	2018-07-01 21:10:08.000000000 +0800
+++ ../b/src/bin/psql/tab-complete.c	2018-07-02 09:56:12.628148298 +0800
@@ -3400,7 +3400,9 @@
 		COMPLETE_WITH_CONST("IS");
 
 /* SELECT */
-	/* naah . . . */
+	/* If we have SELECT <sth>, complete it with "FROM" or "INTO" */
+	else if (Matches2("SELECT", MatchAny))
+		COMPLETE_WITH_LIST2("FROM", "INTO");
 
 /* SET, RESET, SHOW */
 	/* Complete with a variable name */
#2Edmund Horner
ejrh00@gmail.com
In reply to: C,C H (#1)
Re: Add a tab-completion for "SELECT <sth> INTO" or "SELECT <sth> FROM" in psql

On 2 July 2018 at 17:57, C,C H <a12321aabb@gmail.com> wrote:

I use tab-completion in psql quite often and I find that I can't complete
"FROM" for SELECT query.

So I try to create a patch for it.

I download the source code from GitHub master branch and modify the file to
create the patch.

I compile the code and my code change works like follows,
--------------------------------------------------------------
postgres=# SELECT * <Tab Key><Tab Key>
FROM INTO
postgres=# SELECT *
--------------------------------------------------------------

This is my first patch contribution trial here, please correct me if there
is something wrong.

Hi CCHsu,

This looks useful, but it does overlap with my patch to add completion
for column and function names to SELECT -- see
https://commitfest.postgresql.org/18/1376/ . I have been quiet on
this as everyone was (and still is) busy with the 11.0 release.

I also have a patch for columns and functions after a comma in the
select list, but I've been even more quiet on that one.

We can try to combine them. It won't be as simple as your patch here,
unfortunately. Luckily the completions are active at mostly*
different times. Was the last word SELECT ? Offer a column or
function name. Otherwise offer FROM/INTO.

* note that FROM/INTO can also appear directly after SELECT!

Cheers,
Edmund