1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

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 534874fac0), 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
This commit is contained in:
Fujii Masao
2025-06-30 18:36:24 +09:00
parent 9601351146
commit a4c10de929

View File

@ -889,6 +889,14 @@ static const SchemaQuery Query_for_list_of_analyzables = {
.result = "c.relname", .result = "c.relname",
}; };
/*
* Relations supporting COPY TO/FROM are currently almost the same as
* those supporting ANALYZE. Although views with INSTEAD OF INSERT triggers
* can be used with COPY FROM, they are rarely used for this purpose,
* so plain views are intentionally excluded from this tab completion.
*/
#define Query_for_list_of_tables_for_copy Query_for_list_of_analyzables
/* Relations supporting index creation */ /* Relations supporting index creation */
static const SchemaQuery Query_for_list_of_indexables = { static const SchemaQuery Query_for_list_of_indexables = {
.catname = "pg_catalog.pg_class c", .catname = "pg_catalog.pg_class c",
@ -3255,7 +3263,7 @@ match_previous_words(int pattern_id,
* backslash command). * backslash command).
*/ */
else if (Matches("COPY|\\copy")) else if (Matches("COPY|\\copy"))
COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables, "("); COMPLETE_WITH_SCHEMA_QUERY_PLUS(Query_for_list_of_tables_for_copy, "(");
/* Complete COPY ( with legal query commands */ /* Complete COPY ( with legal query commands */
else if (Matches("COPY|\\copy", "(")) else if (Matches("COPY|\\copy", "("))
COMPLETE_WITH("SELECT", "TABLE", "VALUES", "INSERT INTO", "UPDATE", "DELETE FROM", "MERGE INTO", "WITH"); COMPLETE_WITH("SELECT", "TABLE", "VALUES", "INSERT INTO", "UPDATE", "DELETE FROM", "MERGE INTO", "WITH");