Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2023-01-07 Thread vignesh C
On Fri, 6 Jan 2023 at 15:33, Dean Rasheed  wrote:
>
> On Fri, 6 Jan 2023 at 02:38, vignesh C  wrote:
> >
> > On Thu, 5 Jan 2023 at 18:22, Dean Rasheed  wrote:
> > >
> > > That leads to the attached, which barring objections, I'll push shortly.
> >
> > The changes look good to me.
> >
>
> Pushed.

Thanks for pushing this.

Regards,
Vignesh




Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2023-01-06 Thread Dean Rasheed
On Thu, 5 Jan 2023 at 12:52, Dean Rasheed  wrote:
>
> While playing around with this, I noticed that the "... SET SCHEMA"
> case offers "FROM CURRENT" and "TO" as completions, which is
> incorrect. It should really offer to complete with a list of schemas.
> However, since that's a pre-existing bug in a different region of the
> code, I think it's best addressed in a separate patch, which probably
> ought to be back-patched.
>

OK, I've pushed and back-patched a fix for that issue too.

Regards,
Dean




Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2023-01-06 Thread Dean Rasheed
On Fri, 6 Jan 2023 at 02:38, vignesh C  wrote:
>
> On Thu, 5 Jan 2023 at 18:22, Dean Rasheed  wrote:
> >
> > That leads to the attached, which barring objections, I'll push shortly.
>
> The changes look good to me.
>

Pushed.

Regards,
Dean




Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2023-01-05 Thread vignesh C
On Thu, 5 Jan 2023 at 18:22, Dean Rasheed  wrote:
>
> On Tue, 6 Dec 2022 at 19:12, vignesh C  wrote:
> >
> > On Tue, 6 Dec 2022 at 20:42, Melih Mutlu  wrote:
> > >
> > > Also one little suggestion:
> > >
> > >> + if (ends_with(prev_wd, ')'))
> > >> + COMPLETE_WITH(Alter_routine_options, "CALLED ON NULL INPUT",
> > >> +  "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT");
> > >
> > > What do you think about gathering FUNCTION options as you did with 
> > > ROUTINE options.
> > > Something like the following would seem nicer, I think.
> > >
> > >> #define Alter_function_options \
> > >> Alter_routine_options, "CALLED ON NULL INPUT", \
> > >> "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT"
> >
> > I did not make it as a macro for alter function options as it is used
> > only in one place whereas the others were required in more than one
> > place.
>
> My feeling is that having this macro somewhat improves readability and
> consistency between the 3 cases, so I think it's worth it, even if
> it's only used once.
>
> I think it slightly improves readability to keep all the arguments to
> Matches() on one line, and that seems to be the style elsewhere, even
> if that makes the line longer than 80 characters.
>
> Also in the interests of readability, I think it's slightly easier to
> follow if the "ALTER PROCEDURE  (...)" and "ALTER ROUTINE 
> (...)" cases are made to immediately follow the "ALTER FUNCTION 
> (...)" case, with the longer/more complex cases following on from
> that.
>
> That leads to the attached, which barring objections, I'll push shortly.

The changes look good to me.

Regards,
Vignesh




Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2023-01-05 Thread Dean Rasheed
On Tue, 6 Dec 2022 at 19:12, vignesh C  wrote:
>
> On Tue, 6 Dec 2022 at 20:42, Melih Mutlu  wrote:
> >
> > Also one little suggestion:
> >
> >> + if (ends_with(prev_wd, ')'))
> >> + COMPLETE_WITH(Alter_routine_options, "CALLED ON NULL INPUT",
> >> +  "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT");
> >
> > What do you think about gathering FUNCTION options as you did with ROUTINE 
> > options.
> > Something like the following would seem nicer, I think.
> >
> >> #define Alter_function_options \
> >> Alter_routine_options, "CALLED ON NULL INPUT", \
> >> "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT"
>
> I did not make it as a macro for alter function options as it is used
> only in one place whereas the others were required in more than one
> place.

My feeling is that having this macro somewhat improves readability and
consistency between the 3 cases, so I think it's worth it, even if
it's only used once.

I think it slightly improves readability to keep all the arguments to
Matches() on one line, and that seems to be the style elsewhere, even
if that makes the line longer than 80 characters.

Also in the interests of readability, I think it's slightly easier to
follow if the "ALTER PROCEDURE  (...)" and "ALTER ROUTINE 
(...)" cases are made to immediately follow the "ALTER FUNCTION 
(...)" case, with the longer/more complex cases following on from
that.

That leads to the attached, which barring objections, I'll push shortly.

While playing around with this, I noticed that the "... SET SCHEMA"
case offers "FROM CURRENT" and "TO" as completions, which is
incorrect. It should really offer to complete with a list of schemas.
However, since that's a pre-existing bug in a different region of the
code, I think it's best addressed in a separate patch, which probably
ought to be back-patched.

Regards,
Dean
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
new file mode 100644
index 5312a7e..b07257c
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1149,6 +1149,21 @@ static const SchemaQuery Query_for_trigg
 "CREATE", "CONNECT", "TEMPORARY", "EXECUTE", "USAGE", "SET", "ALTER SYSTEM", \
 "MAINTAIN", "ALL"
 
+/* ALTER PROCEDURE options */
+#define Alter_procedure_options \
+"DEPENDS ON EXTENSION", "EXTERNAL SECURITY", "NO DEPENDS ON EXTENSION", \
+"OWNER TO", "RENAME TO", "RESET", "SECURITY", "SET"
+
+/* ALTER ROUTINE options */
+#define Alter_routine_options \
+Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
+"PARALLEL", "ROWS", "STABLE", "VOLATILE"
+
+/* ALTER FUNCTION options */
+#define Alter_function_options \
+Alter_routine_options, "CALLED ON NULL INPUT", "RETURNS NULL ON NULL INPUT", \
+"STRICT", "SUPPORT"
+
 /*
  * These object types were introduced later than our support cutoff of
  * server version 9.2.  We use the VersionedQuery infrastructure so that
@@ -1812,15 +1827,45 @@ psql_completion(const char *text, int st
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
-	/* ALTER FUNCTION,PROCEDURE,ROUTINE  (...) */
-	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny))
+	/* ALTER FUNCTION  (...) */
+	else if (Matches("ALTER", "FUNCTION", MatchAny, MatchAny))
 	{
 		if (ends_with(prev_wd, ')'))
-			COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA",
-		  "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION");
+			COMPLETE_WITH(Alter_function_options);
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
+	/* ALTER PROCEDURE  (...) */
+	else if (Matches("ALTER", "PROCEDURE", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH(Alter_procedure_options);
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER ROUTINE  (...) */
+	else if (Matches("ALTER", "ROUTINE", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH(Alter_routine_options);
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER FUNCTION|ROUTINE  (...) PARALLEL */
+	else if (Matches("ALTER", "FUNCTION|ROUTINE", MatchAny, MatchAny, "PARALLEL"))
+		COMPLETE_WITH("RESTRICTED", "SAFE", "UNSAFE");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) [EXTERNAL] SECURITY */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "SECURITY") ||
+			 Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "EXTERNAL", "SECURITY"))
+		COMPLETE_WITH("DEFINER", "INVOKER");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) RESET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "RESET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "ALL");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) SET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny, "SET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "SCHEMA");
 
 	/* ALTER PUBLICATION  */
 	else if (Matches("ALTER", "PUBLICATION", MatchAny))


Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2022-12-07 Thread Melih Mutlu
Hi,

vignesh C , 6 Ara 2022 Sal, 22:12 tarihinde şunu yazdı:

> I did not make it as a macro for alter function options as it is used
> only in one place whereas the others were required in more than one
> place.
>

Okay, makes sense.

I tested the patch and it worked for me.

Best,
--
Melih Mutlu
Microsoft


Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2022-12-06 Thread vignesh C
On Tue, 6 Dec 2022 at 20:42, Melih Mutlu  wrote:
>
> Hi Vignesh,
>
> Looks like the patch needs a rebase.

Rebased

> Also one little suggestion:
>
>> + if (ends_with(prev_wd, ')'))
>> + COMPLETE_WITH(Alter_routine_options, "CALLED ON NULL INPUT",
>> +  "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT");
>
>
> What do you think about gathering FUNCTION options as you did with ROUTINE 
> options.
> Something like the following would seem nicer, I think.
>
>> #define Alter_function_options \
>> Alter_routine_options, "CALLED ON NULL INPUT", \
>>
>> "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT"

I did not make it as a macro for alter function options as it is used
only in one place whereas the others were required in more than one
place.
The attached v4 patch is rebased on top of HEAD.

Regards,
Vignesh
From c1436c498d1d939384999ecb508d5da3403abc90 Mon Sep 17 00:00:00 2001
From: Vignesh C 
Date: Wed, 7 Dec 2022 00:27:37 +0530
Subject: [PATCH v4] Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE.

Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE action was missing,
added the tab completion for the same.
---
 src/bin/psql/tab-complete.c | 57 ++---
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 89e7317c23..105517e61e 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1149,6 +1149,16 @@ static const SchemaQuery Query_for_trigger_of_table = {
 "CREATE", "CONNECT", "TEMPORARY", "EXECUTE", "USAGE", "SET", "ALTER SYSTEM", \
 "VACUUM", "ANALYZE", "ALL"
 
+/* ALTER PROCEDURE options */
+#define Alter_procedure_options \
+"DEPENDS ON EXTENSION", "EXTERNAL SECURITY", "NO DEPENDS ON EXTENSION", \
+"OWNER TO", "RENAME TO", "RESET", "SECURITY", "SET"
+
+/* ALTER ROUTINE options */
+#define Alter_routine_options \
+Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
+"PARALLEL", "ROWS", "STABLE", "VOLATILE"
+
 /*
  * These object types were introduced later than our support cutoff of
  * server version 9.2.  We use the VersionedQuery infrastructure so that
@@ -1812,12 +1822,51 @@ psql_completion(const char *text, int start, int end)
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
-	/* ALTER FUNCTION,PROCEDURE,ROUTINE  (...) */
-	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny))
+	/* ALTER FUNCTION  (...) */
+	else if (Matches("ALTER", "FUNCTION", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH(Alter_routine_options, "CALLED ON NULL INPUT",
+		  "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT");
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER FUNCTION|ROUTINE  (...) PARALLEL */
+	else if (Matches("ALTER", "FUNCTION|ROUTINE", MatchAny, MatchAny,
+			 "PARALLEL"))
+		COMPLETE_WITH("RESTRICTED", "SAFE", "UNSAFE");
+	/*
+	 * ALTER FUNCTION|PROCEDURE|ROUTINE  (...)
+	 * [EXTERNAL] SECURITY
+	 */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "SECURITY") ||
+			 Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "EXTERNAL", "SECURITY"))
+		COMPLETE_WITH("DEFINER" ,"INVOKER");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) RESET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "RESET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "ALL");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) SET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "SET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "SCHEMA");
+	/* ALTER PROCEDURE  (...) */
+	else if (Matches("ALTER", "PROCEDURE", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH(Alter_procedure_options);
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER ROUTINE  (...) */
+	else if (Matches("ALTER", "ROUTINE", MatchAny, MatchAny))
 	{
 		if (ends_with(prev_wd, ')'))
-			COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA",
-		  "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION");
+			COMPLETE_WITH(Alter_routine_options);
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
-- 
2.34.1



Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2022-12-06 Thread Melih Mutlu
Hi Vignesh,

Looks like the patch needs a rebase.

Also one little suggestion:

+ if (ends_with(prev_wd, ')'))
> + COMPLETE_WITH(Alter_routine_options, "CALLED ON NULL INPUT",
> +  "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT");


What do you think about gathering FUNCTION options as you did with ROUTINE
options.
Something like the following would seem nicer, I think.

#define Alter_function_options \
> Alter_routine_options, "CALLED ON NULL INPUT", \

"RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT"


Best,
--
Melih Mutlu
Microsoft


Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2022-11-21 Thread vignesh C
On Tue, 22 Nov 2022 at 05:59, Michael Paquier  wrote:
>
> On Fri, Oct 28, 2022 at 05:34:37PM +0530, vignesh C wrote:
> > Those also should be handled, attached v2 version includes the changes
> > for the same.
>
> The basic options supported by PROCEDURE are a subset of ROUTINE with a
> difference of COST, IMMUTABLE, [NOT] LEAKPROOF, ROWS, STABLE
> and VOLATILE.
>
> The basic options supported by ROUTINE are a subset of FUNCTION with a
> difference of { CALLED | RETURNS NULL } ON NULL INPUT, STRICT and
> SUPPORT.  Is it worth refactoring a bit with common lists?

Modified

> +   "RESET", "RETURNS NULL ON NULL INPUT ", "ROWS",
> Extra space after INPUT here, that's easy to miss.

Good catch, the attached v3 patch has the changes for the same.

Regards,
Vignesh
From fab9d9f34979650a63b3be59ea69962923ac6617 Mon Sep 17 00:00:00 2001
From: "vignesh.c" 
Date: Thu, 27 Oct 2022 14:00:46 +0530
Subject: [PATCH v3] Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE.

Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE action was missing,
added the tab completion for the same.
---
 src/bin/psql/tab-complete.c | 57 ++---
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 13014f074f..4d0bbc034d 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1149,6 +1149,16 @@ static const SchemaQuery Query_for_trigger_of_table = {
 "CREATE", "CONNECT", "TEMPORARY", "EXECUTE", "USAGE", "SET", "ALTER SYSTEM", \
 "ALL"
 
+/* ALTER PROCEDURE options */
+#define Alter_procedure_options \
+"DEPENDS ON EXTENSION", "EXTERNAL SECURITY", "NO DEPENDS ON EXTENSION", \
+"OWNER TO", "RENAME TO", "RESET", "SECURITY", "SET"
+
+/* ALTER ROUTINE options */
+#define Alter_routine_options \
+Alter_procedure_options, "COST", "IMMUTABLE", "LEAKPROOF", "NOT LEAKPROOF", \
+"PARALLEL", "ROWS", "STABLE", "VOLATILE"
+
 /*
  * These object types were introduced later than our support cutoff of
  * server version 9.2.  We use the VersionedQuery infrastructure so that
@@ -1812,12 +1822,51 @@ psql_completion(const char *text, int start, int end)
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
-	/* ALTER FUNCTION,PROCEDURE,ROUTINE  (...) */
-	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny))
+	/* ALTER FUNCTION  (...) */
+	else if (Matches("ALTER", "FUNCTION", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH(Alter_routine_options, "CALLED ON NULL INPUT",
+		  "RETURNS NULL ON NULL INPUT", "STRICT", "SUPPORT");
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER FUNCTION|ROUTINE  (...) PARALLEL */
+	else if (Matches("ALTER", "FUNCTION|ROUTINE", MatchAny, MatchAny,
+			 "PARALLEL"))
+		COMPLETE_WITH("RESTRICTED", "SAFE", "UNSAFE");
+	/*
+	 * ALTER FUNCTION|PROCEDURE|ROUTINE  (...)
+	 * [EXTERNAL] SECURITY
+	 */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "SECURITY") ||
+			 Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "EXTERNAL", "SECURITY"))
+		COMPLETE_WITH("DEFINER" ,"INVOKER");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) RESET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "RESET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "ALL");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) SET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "SET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "SCHEMA");
+	/* ALTER PROCEDURE  (...) */
+	else if (Matches("ALTER", "PROCEDURE", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH(Alter_procedure_options);
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER ROUTINE  (...) */
+	else if (Matches("ALTER", "ROUTINE", MatchAny, MatchAny))
 	{
 		if (ends_with(prev_wd, ')'))
-			COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA",
-		  "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION");
+			COMPLETE_WITH(Alter_routine_options);
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
-- 
2.34.1



Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2022-11-21 Thread Michael Paquier
On Fri, Oct 28, 2022 at 05:34:37PM +0530, vignesh C wrote:
> Those also should be handled, attached v2 version includes the changes
> for the same.

The basic options supported by PROCEDURE are a subset of ROUTINE with a
difference of COST, IMMUTABLE, [NOT] LEAKPROOF, ROWS, STABLE 
and VOLATILE.

The basic options supported by ROUTINE are a subset of FUNCTION with a
difference of { CALLED | RETURNS NULL } ON NULL INPUT, STRICT and
SUPPORT.  Is it worth refactoring a bit with common lists?

+   "RESET", "RETURNS NULL ON NULL INPUT ", "ROWS",
Extra space after INPUT here, that's easy to miss.
--
Michael


signature.asc
Description: PGP signature


Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2022-10-28 Thread vignesh C
On Fri, 28 Oct 2022 at 08:02, Dong Wook Lee  wrote:
>
> On Fri, Oct 28, 2022 at 12:08 AM vignesh C  wrote:
> >
> > Hi,
> >
> > Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE action was
> > missing, this patch adds the tab completion for the same.
> >
> > Regards,
> > Vignesh
>
> Hi,
> I applied your patch and did some tests.
> Is it okay not to consider SET and RESET commands? (e.g ALTER FUNCTION)

Those also should be handled, attached v2 version includes the changes
for the same.

Regards,
Vignesh
From ed4129144f09d003999028802d2d20e03ce93462 Mon Sep 17 00:00:00 2001
From: "vignesh.c" 
Date: Thu, 27 Oct 2022 14:00:46 +0530
Subject: [PATCH v2] Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE.

Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE action was missing,
added the tab completion for the same.
---
 src/bin/psql/tab-complete.c | 58 ++---
 1 file changed, 54 insertions(+), 4 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index a64571215b..63b9d48c3b 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1805,12 +1805,62 @@ psql_completion(const char *text, int start, int end)
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
-	/* ALTER FUNCTION,PROCEDURE,ROUTINE  (...) */
-	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny))
+	/* ALTER FUNCTION  (...) */
+	else if (Matches("ALTER", "FUNCTION", MatchAny, MatchAny))
 	{
 		if (ends_with(prev_wd, ')'))
-			COMPLETE_WITH("OWNER TO", "RENAME TO", "SET SCHEMA",
-		  "DEPENDS ON EXTENSION", "NO DEPENDS ON EXTENSION");
+			COMPLETE_WITH("CALLED ON NULL INPUT", "COST",
+		  "DEPENDS ON EXTENSION", "EXTERNAL SECURITY",
+		  "IMMUTABLE", "LEAKPROOF", "NO DEPENDS ON EXTENSION",
+		  "NOT LEAKPROOF", "OWNER TO", "PARALLEL", "RENAME TO",
+		  "RESET", "RETURNS NULL ON NULL INPUT ", "ROWS",
+		  "SECURITY", "SET", "STABLE", "STRICT", "SUPPORT",
+		  "VOLATILE");
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER FUNCTION|ROUTINE  (...) PARALLEL */
+	else if (Matches("ALTER", "FUNCTION|ROUTINE", MatchAny, MatchAny,
+			 "PARALLEL"))
+		COMPLETE_WITH("RESTRICTED", "SAFE", "UNSAFE");
+	/*
+	 * ALTER FUNCTION|PROCEDURE|ROUTINE  (...)
+	 * [EXTERNAL] SECURITY
+	 */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "SECURITY") ||
+			 Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "EXTERNAL", "SECURITY"))
+		COMPLETE_WITH("DEFINER" ,"INVOKER");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) RESET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "RESET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "ALL");
+	/* ALTER FUNCTION|PROCEDURE|ROUTINE  (...) SET */
+	else if (Matches("ALTER", "FUNCTION|PROCEDURE|ROUTINE", MatchAny, MatchAny,
+	 "SET"))
+		COMPLETE_WITH_QUERY_VERBATIM_PLUS(Query_for_list_of_set_vars,
+		  "SCHEMA");
+	/* ALTER PROCEDURE  (...) */
+	else if (Matches("ALTER", "PROCEDURE", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH("DEPENDS ON EXTENSION", "EXTERNAL SECURITY",
+		  "NO DEPENDS ON EXTENSION", "OWNER TO", "RENAME TO",
+		  "RESET", "SECURITY", "SET");
+		else
+			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
+	}
+	/* ALTER ROUTINE  (...) */
+	else if (Matches("ALTER", "ROUTINE", MatchAny, MatchAny))
+	{
+		if (ends_with(prev_wd, ')'))
+			COMPLETE_WITH("COST", "DEPENDS ON EXTENSION", "EXTERNAL SECURITY",
+		  "IMMUTABLE", "LEAKPROOF", "NO DEPENDS ON EXTENSION",
+		  "NOT LEAKPROOF", "OWNER TO", "PARALLEL", "RENAME TO",
+		  "RESET", "ROWS", "SECURITY", "SET", "STABLE",
+		  "VOLATILE");
 		else
 			COMPLETE_WITH_FUNCTION_ARG(prev2_wd);
 	}
-- 
2.32.0



Re: Improve tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE

2022-10-27 Thread Dong Wook Lee
On Fri, Oct 28, 2022 at 12:08 AM vignesh C  wrote:
>
> Hi,
>
> Tab completion for ALTER FUNCTION/PROCEDURE/ROUTINE action was
> missing, this patch adds the tab completion for the same.
>
> Regards,
> Vignesh

Hi,
I applied your patch and did some tests.
Is it okay not to consider SET and RESET commands? (e.g ALTER FUNCTION)

---
Regards,
DongWook Lee.