Add a few new patterns to the tab completion of psql
authorMichael Paquier <[email protected]>
Wed, 5 Oct 2022 02:46:10 +0000 (11:46 +0900)
committerMichael Paquier <[email protected]>
Wed, 5 Oct 2022 02:46:10 +0000 (11:46 +0900)
This improves the tab completion of psql on a few points:
- Provide a list of subscriptions on \dRs.
- Provide a list of publications on \dRp.
- Add CURRENT_ROLE, CURRENT_USER, SESSION_USER when OWNER TO is provided
at the end of a query (as defined by RoleSpec in gram.y).

Author: Vignesh C
Reviewed-by: Dagfinn Ilmari Mannsåker
Discussion: https://postgr.es/m/CALDaNm3toRBt6c6saY3174f7CsGztXRvVvfWbikkJEXY7x5WAA@mail.gmail.com

src/bin/psql/tab-complete.c

index 71cfe8aec151d783925dd3bef5082baf47fea000..584d9d5ae642b6fa43c7aaabc93d4792b269478d 100644 (file)
@@ -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"))
@@ -4614,6 +4617,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*"))