Fix tab completion of ALTER FUNCTION/PROCEDURE/ROUTINE ... SET SCHEMA.
authorDean Rasheed <[email protected]>
Fri, 6 Jan 2023 11:15:22 +0000 (11:15 +0000)
committerDean Rasheed <[email protected]>
Fri, 6 Jan 2023 11:15:22 +0000 (11:15 +0000)
The ALTER DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER ... SET <name>
case in psql tab completion failed to exclude <name> = "SCHEMA", which
caused ALTER FUNCTION|PROCEDURE|ROUTINE ... SET SCHEMA to complete
with "FROM CURRENT" and "TO", which won't work.

Fix that, so that those cases now complete with the list of schemas,
like other ALTER ... SET SCHEMA commands.

Noticed while testing the recent patch to improve tab completion for
ALTER FUNCTION/PROCEDURE/ROUTINE, but this is not directly related to
that patch. Rather, this is a long-standing bug, so back-patch to all
supported branches.

Discussion: https://postgr.es/m/CALDaNm0s7GQmkLP_mx5Cvk=UzYMnjhPmXBxU8DsHEunFbC5sTg@mail.gmail.com

src/bin/psql/tab-complete.c

index 49ec2b0a388c4873ceac861fd85663fa08e7f701..5b909d6f3a045488ee5434b742ad7086ff56fedb 100644 (file)
@@ -3793,11 +3793,12 @@ psql_completion(const char *text, int start, int end)
        COMPLETE_WITH("TO");
 
    /*
-    * Complete ALTER DATABASE|FUNCTION||PROCEDURE|ROLE|ROUTINE|USER ... SET
+    * Complete ALTER DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER ... SET
     * <name>
     */
    else if (HeadMatches("ALTER", "DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER") &&
-            TailMatches("SET", MatchAny))
+            TailMatches("SET", MatchAny) &&
+            !TailMatches("SCHEMA"))
        COMPLETE_WITH("FROM CURRENT", "TO");
 
    /*