Skip to content

Commit f2bbadc

Browse files
committed
Add tab completion for data types after ALTER TABLE ADD [COLUMN] in psql
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
1 parent 99709c9 commit f2bbadc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/bin/psql/tab-complete.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,8 +2025,16 @@ psql_completion(const char *text, int start, int end)
20252025
"DETACH PARTITION", "FORCE ROW LEVEL SECURITY");
20262026
/* ALTER TABLE xxx ADD */
20272027
else if (Matches("ALTER", "TABLE", MatchAny, "ADD"))
2028+
{
2029+
/* make sure to keep this list and the !Matches() below in sync */
20282030
COMPLETE_WITH("COLUMN", "CONSTRAINT", "CHECK", "UNIQUE", "PRIMARY KEY",
20292031
"EXCLUDE", "FOREIGN KEY");
2032+
}
2033+
/* ATER TABLE xxx ADD [COLUMN] yyy */
2034+
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN", MatchAny) ||
2035+
(Matches("ALTER", "TABLE", MatchAny, "ADD", MatchAny) &&
2036+
!Matches("ALTER", "TABLE", MatchAny, "ADD", "COLUMN|CONSTRAINT|CHECK|UNIQUE|PRIMARY|EXCLUDE|FOREIGN")))
2037+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes, NULL);
20302038
/* ALTER TABLE xxx ADD CONSTRAINT yyy */
20312039
else if (Matches("ALTER", "TABLE", MatchAny, "ADD", "CONSTRAINT", MatchAny))
20322040
COMPLETE_WITH("CHECK", "UNIQUE", "PRIMARY KEY", "EXCLUDE", "FOREIGN KEY");

0 commit comments

Comments
 (0)