Add tab completion for data types after ALTER TABLE ADD [COLUMN] in psql
authorMichael Paquier <michael@paquier.xyz>
Tue, 31 Aug 2021 03:07:20 +0000 (12:07 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 31 Aug 2021 03:07:47 +0000 (12:07 +0900)
This allows finding data types that can be used for the creation of a
new column, completing d3fa876.

Author: Dagfinn Ilmari MannsÃ¥ker
Discussion: https://postgr.es/m/87h7f7uk6s.fsf@wibble.ilmari.org

src/bin/psql/tab-complete.c

index 7c6af435a950aa7793fd72bd61bd67ff8ae727b1..76462412db59a403d446c28ea7594dadef958640 100644 (file)
@@ -2025,8 +2025,16 @@ psql_completion(const char *text, int start, int end)
                      "DETACH PARTITION", "FORCE ROW LEVEL SECURITY");
    /* ALTER TABLE xxx ADD */
    else if (Matches("ALTER", "TABLE", MatchAny, "ADD"))
+   {
+       /* make sure to keep this list and the !Matches() below in sync */
        COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY",
                      "EXCLUDE", "FOREIGN KEY");
+   }
+   /* ATER TABLE xxx ADD [COLUMN] yyy */
+   else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", MatchAny) ||
+            (Matches("ALTER", "TABLE", MatchAny, "ADD", MatchAny) &&
+             !Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|EXCLUDE|FOREIGN")))
+       COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL);
    /* ALTER TABLE xxx ADD CONSTRAINT yyy */
    else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny))
        COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY");