diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index b64db82f029..d7779925599 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -609,6 +609,14 @@ static const SchemaQuery Query_for_list_of_statistics = { .result = "pg_catalog.quote_ident(s.stxname)", }; +static const SchemaQuery Query_for_list_of_collations = { + .catname = "pg_catalog.pg_collation c", + .selcondition = "c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))", + .viscondition = "pg_catalog.pg_collation_is_visible(c.oid)", + .namespace = "c.collnamespace", + .result = "pg_catalog.quote_ident(c.collname)", +}; + /* * Queries to get lists of names of various kinds of things, possibly @@ -1031,7 +1039,7 @@ static const pgsql_thing_t words_after_create[] = { {"AGGREGATE", NULL, NULL, Query_for_list_of_aggregates}, {"CAST", NULL, NULL, NULL}, /* Casts have complex structures for names, so * skip it */ - {"COLLATION", "SELECT pg_catalog.quote_ident(collname) FROM pg_catalog.pg_collation WHERE collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding())) AND substring(pg_catalog.quote_ident(collname),1,%d)='%s'"}, + {"COLLATION", NULL, NULL, &Query_for_list_of_collations}, /* * CREATE CONSTRAINT TRIGGER is not supported here because it is designed @@ -2433,6 +2441,22 @@ psql_completion(const char *text, int start, int end) else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE", MatchAny)) COMPLETE_WITH("HANDLER"); + /* CREATE COLLATION */ + else if (Matches("CREATE", "COLLATION", MatchAny)) + COMPLETE_WITH("(", "FROM"); + else if (Matches("CREATE", "COLLATION", MatchAny, "FROM")) + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_collations, NULL); + else if (HeadMatches("CREATE", "COLLATION", MatchAny, "(*")) + { + if (TailMatches("(|*,")) + COMPLETE_WITH("LOCALE =", "LC_COLLATE =", "LC_CTYPE =", + "PROVIDER =", "DETERMINISTIC ="); + else if (TailMatches("PROVIDER", "=")) + COMPLETE_WITH("libc", "icu"); + else if (TailMatches("DETERMINISTIC", "=")) + COMPLETE_WITH("true", "false"); + } + /* CREATE DATABASE */ else if (Matches("CREATE", "DATABASE", MatchAny)) COMPLETE_WITH("OWNER", "TEMPLATE", "ENCODING", "TABLESPACE",