Skip to content

Commit a4c10de

Browse files
committed
psql: Improve tab completion for COPY command.
Previously, tab completion for COPY only suggested plain tables and partitioned tables, even though materialized views are also valid for COPY TO (since commit 534874f), and foreign tables are valid for COPY FROM. This commit enhances tab completion for COPY to also include materialized views and foreign tables. Views with INSTEAD OF INSERT triggers are supported with COPY FROM but rarely used, so plain views are intentionally excluded from completion. Author: jian he <jian.universality@gmail.com> Co-authored-by: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: David G. Johnston <david.g.johnston@gmail.com> Discussion: https://postgr.es/m/CACJufxFxnSkikp+GormAGHcMTX1YH2HRXW1+3dJM9w7yY9hdsg@mail.gmail.com
1 parent 9601351 commit a4c10de

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/bin/psql/tab-complete.in.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,14 @@ static const SchemaQuery Query_for_list_of_analyzables = {
889889
.result = "c.relname",
890890
};
891891

892+
/*
893+
* Relations supporting COPY TO/FROM are currently almost the same as
894+
* those supporting ANALYZE. Although views with INSTEAD OF INSERT triggers
895+
* can be used with COPY FROM, they are rarely used for this purpose,
896+
* so plain views are intentionally excluded from this tab completion.
897+
*/
898+
#define Query_for_list_of_tables_for_copy Query_for_list_of_analyzables
899+
892900
/* Relations supporting index creation */
893901
static const SchemaQuery Query_for_list_of_indexables = {
894902
.catname = "pg_catalog.pg_class c",
@@ -3255,7 +3263,7 @@ match_previous_words(int pattern_id,
32553263
* backslash command).
32563264
*/
32573265
else if (Matches("COPY|\\copy"))
3258-
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables, "(");
3266+
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables_for_copy, "(");
32593267
/* Complete COPY ( with legal query commands */
32603268
else if (Matches("COPY|\\copy", "("))
32613269
COMPLETE_WITH("SELECT", "TABLE", "VALUES", "INSERT INTO", "UPDATE", "DELETE FROM", "MERGE INTO", "WITH");

0 commit comments

Comments
 (0)