On Tue, 4 Oct 2022 at 09:13, Michael Paquier <mich...@paquier.xyz> wrote:
>
> On Mon, Oct 03, 2022 at 06:29:32PM +0100, Dagfinn Ilmari Mannsåker wrote:
> > vignesh C <vignes...@gmail.com> writes:
> >> +    else if (TailMatchesCS("\\dRp*"))
> >> +            COMPLETE_WITH_QUERY(Query_for_list_of_publications[0].query);
> >> +    else if (TailMatchesCS("\\dRs*"))
> >> +            COMPLETE_WITH_QUERY(Query_for_list_of_subscriptions[0].query);
> >
> > These are version-specific queries, so should be passed in their
> > entirety to COMPLETE_WITH_VERSIONED_QUERY() so that psql can pick the
> > right version, and avoid sending the query at all if the server is too
> > old.
>
> +1.
>

Modified

 >> +/* add these to Query_for_list_of_roles in OWNER TO contexts */
> >> +#define Keywords_for_list_of_owner_to_roles \
> >> +"CURRENT_ROLE", "CURRENT_USER", "SESSION_USER"
> >
> > I think this would read better without the TO, both in the comment and
> > the constant name, similar to the below only having GRANT without TO:
>
> Keywords_for_list_of_grant_roles is used in six code paths, so it
> seems to me that there is little gain in having a separate #define
> here.  Let's just specify the list of allowed roles (RoleSpec) where
> OWNER TO is parsed.

I have removed the macro and specified the allowed roles.

Thanks for the comments, the attached v2 patch has the changes for the same.

Regards,
Vignesh
From 525eb4d3959f316338160bfbcc769f64c16310a0 Mon Sep 17 00:00:00 2001
From: Vignesh C <vignes...@gmail.com>
Date: Sun, 2 Oct 2022 10:59:59 +0530
Subject: [PATCH v2 2/2] Include CURRENT_ROLE, CURRENT_USER and SESSION_USER in
 tab completion while changing owner.

Include CURRENT_ROLE, CURRENT_USER and SESSION_USER in tab completion
while changing owner.
---
 src/bin/psql/tab-complete.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 2818fb26a0..584d9d5ae6 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -4160,7 +4160,10 @@ psql_completion(const char *text, int start, int end)
 
 /* OWNER TO  - complete with available roles */
 	else if (TailMatches("OWNER", "TO"))
-		COMPLETE_WITH_QUERY(Query_for_list_of_roles);
+		COMPLETE_WITH_QUERY_PLUS(Query_for_list_of_roles,
+								 "CURRENT_ROLE",
+								 "CURRENT_USER",
+								 "SESSION_USER");
 
 /* ORDER BY */
 	else if (TailMatches("FROM", MatchAny, "ORDER"))
-- 
2.32.0

From 890ac3d01ecd4238572047e738a80acd1a5c7a67 Mon Sep 17 00:00:00 2001
From: Vignesh C <vignes...@gmail.com>
Date: Sun, 2 Oct 2022 10:45:04 +0530
Subject: [PATCH v2 1/2] Display publications and subscriptions for tab
 completion of \dRp and \dRs.

Display publications and subscriptions for tab completion of \dRp and
\dRs.
---
 src/bin/psql/tab-complete.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 71cfe8aec1..2818fb26a0 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -4614,6 +4614,10 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_tables);
 	else if (TailMatchesCS("\\dP*"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_partitioned_relations);
+	else if (TailMatchesCS("\\dRp*"))
+		COMPLETE_WITH_VERSIONED_QUERY(Query_for_list_of_publications);
+	else if (TailMatchesCS("\\dRs*"))
+		COMPLETE_WITH_VERSIONED_QUERY(Query_for_list_of_subscriptions);
 	else if (TailMatchesCS("\\ds*"))
 		COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_sequences);
 	else if (TailMatchesCS("\\dt*"))
-- 
2.32.0

Reply via email to