Skip to content

Commit 81e094b

Browse files
committed
Support tab-complete for TRUNCATE on foreign tables.
Commit 8ff1c94 extended TRUNCATE command so that it can also truncate foreign tables. But it forgot to support tab-complete for TRUNCATE on foreign tables. That is, previously tab-complete for TRUNCATE displayed only the names of regular tables. This commit improves tab-complete for TRUNCATE so that it displays also the names of foreign tables. Author: Fujii Masao Reviewed-by: Bharath Rupireddy Discussion: https://postgr.es/m/551ed8c1-f531-818b-664a-2cecdab99cd8@oss.nttdata.com
1 parent b094063 commit 81e094b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/bin/psql/tab-complete.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,18 @@ static const SchemaQuery Query_for_list_of_selectables = {
549549
.result = "pg_catalog.quote_ident(c.relname)",
550550
};
551551

552+
/* Relations supporting TRUNCATE */
553+
static const SchemaQuery Query_for_list_of_truncatables = {
554+
.catname = "pg_catalog.pg_class c",
555+
.selcondition =
556+
"c.relkind IN (" CppAsString2(RELKIND_RELATION) ", "
557+
CppAsString2(RELKIND_FOREIGN_TABLE) ", "
558+
CppAsString2(RELKIND_PARTITIONED_TABLE) ")",
559+
.viscondition = "pg_catalog.pg_table_is_visible(c.oid)",
560+
.namespace = "c.relnamespace",
561+
.result = "pg_catalog.quote_ident(c.relname)",
562+
};
563+
552564
/* Relations supporting GRANT are currently same as those supporting SELECT */
553565
#define Query_for_list_of_grantables Query_for_list_of_selectables
554566

@@ -3834,14 +3846,14 @@ psql_completion(const char *text, int start, int end)
38343846

38353847
/* TRUNCATE */
38363848
else if (Matches("TRUNCATE"))
3837-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
3849+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_truncatables,
38383850
" UNION SELECT 'TABLE'"
38393851
" UNION SELECT 'ONLY'");
38403852
else if (Matches("TRUNCATE", "TABLE"))
3841-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
3853+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_truncatables,
38423854
" UNION SELECT 'ONLY'");
38433855
else if (HeadMatches("TRUNCATE") && TailMatches("ONLY"))
3844-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables, NULL);
3856+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_truncatables, NULL);
38453857
else if (Matches("TRUNCATE", MatchAny) ||
38463858
Matches("TRUNCATE", "TABLE|ONLY", MatchAny) ||
38473859
Matches("TRUNCATE", "TABLE", "ONLY", MatchAny))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy