Hi,Currently, the psql's tab completion feature does not support properly for ATTACH PARTITION. When <TAB> key is typed after "ALTER TABLE <table_name> ATTACH PARTITION ", all possible table names should be displayed, however, foreign table names are not displayed. So I created a patch that addresses this issue by ensuring that psql displays not only normal table names but also foreign table names in this case.
Any kind of feedback is appreciated. Best, Tung Nguyen
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 779fdc90cb..174cf5e1dd 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -865,6 +865,18 @@ static const SchemaQuery Query_for_list_of_truncatables = { .result = "c.relname", }; +/* Relations supporting ATTACH PARTITION */ +static const SchemaQuery Query_for_list_of_attachables = { + .catname = "pg_catalog.pg_class c", + .selcondition = + "c.relkind IN (" CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_FOREIGN_TABLE) ", " + CppAsString2(RELKIND_PARTITIONED_TABLE) ")", + .viscondition = "pg_catalog.pg_table_is_visible(c.oid)", + .namespace = "c.relnamespace", + .result = "c.relname", +}; + /* Relations supporting GRANT are currently same as those supporting SELECT */ #define Query_for_list_of_grantables Query_for_list_of_selectables @@ -2567,7 +2579,7 @@ psql_completion(const char *text, int start, int end) * tables. */ else if (Matches("ALTER", "TABLE", MatchAny, "ATTACH", "PARTITION")) - COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables); + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_attachables); /* Limited completion support for partition bound specification */ else if (TailMatches("ATTACH", "PARTITION", MatchAny)) COMPLETE_WITH("FOR VALUES", "DEFAULT");