diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 8c48881..a1bfeab 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -2329,34 +2329,44 @@ psql_completion(const char *text, int start, int end) else if (pg_strcasecmp(prev2_wd, "CREATE") == 0 && pg_strcasecmp(prev_wd, "UNIQUE") == 0) COMPLETE_WITH_CONST("INDEX"); - /* If we have CREATE|UNIQUE INDEX, then add "ON" and existing indexes */ + /* + * If we have CREATE|UNIQUE INDEX, then add "ON", "CONCURRENTLY" + * and existing indexes. + */ else if (pg_strcasecmp(prev_wd, "INDEX") == 0 && (pg_strcasecmp(prev2_wd, "CREATE") == 0 || pg_strcasecmp(prev2_wd, "UNIQUE") == 0)) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, " UNION SELECT 'ON'" " UNION SELECT 'CONCURRENTLY'"); - /* Complete ... INDEX [] ON with a list of tables */ + /* Complete ... INDEX|CONCURRENTLY [] ON with a list of tables */ else if ((pg_strcasecmp(prev3_wd, "INDEX") == 0 || pg_strcasecmp(prev2_wd, "INDEX") == 0 || + pg_strcasecmp(prev3_wd, "CONCURRENTLY") == 0 || pg_strcasecmp(prev2_wd, "CONCURRENTLY") == 0) && pg_strcasecmp(prev_wd, "ON") == 0) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tm, NULL); - /* If we have CREATE|UNIQUE INDEX CONCURRENTLY, then add "ON" */ + /* + * If we have CREATE|UNIQUE INDEX CONCURRENTLY, then add "ON" and + * existing indexes. + */ else if ((pg_strcasecmp(prev3_wd, "INDEX") == 0 || pg_strcasecmp(prev2_wd, "INDEX") == 0) && pg_strcasecmp(prev_wd, "CONCURRENTLY") == 0) - COMPLETE_WITH_CONST("ON"); - /* If we have CREATE|UNIQUE INDEX , then add "ON" or "CONCURRENTLY" */ + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_indexes, + " UNION SELECT 'ON'"); + /* If we have CREATE|UNIQUE INDEX |!CONCURRENTLY, then add "ON" */ else if ((pg_strcasecmp(prev3_wd, "CREATE") == 0 || pg_strcasecmp(prev3_wd, "UNIQUE") == 0) && - pg_strcasecmp(prev2_wd, "INDEX") == 0) - { - static const char *const list_CREATE_INDEX[] = - {"CONCURRENTLY", "ON", NULL}; - - COMPLETE_WITH_LIST(list_CREATE_INDEX); - } + pg_strcasecmp(prev2_wd, "INDEX") == 0 && + pg_strcasecmp(prev_wd, "CONCURRENTLY") != 0) + COMPLETE_WITH_CONST("ON"); + /* If we have CREATE|UNIQUE INDEX CONCURRENTLY , then add "ON" */ + else if ((pg_strcasecmp(prev4_wd, "CREATE") == 0 || + pg_strcasecmp(prev4_wd, "UNIQUE") == 0) && + pg_strcasecmp(prev3_wd, "INDEX") == 0 && + pg_strcasecmp(prev2_wd, "CONCURRENTLY") == 0) + COMPLETE_WITH_CONST("ON"); /* * Complete INDEX ON with a list of table columns (which