Tab-complete CREATE COLLATION.
authorThomas Munro <[email protected]>
Mon, 22 Feb 2021 10:17:31 +0000 (23:17 +1300)
committerThomas Munro <[email protected]>
Mon, 22 Feb 2021 11:16:16 +0000 (00:16 +1300)
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/20210117215940.GE8560%40telsasoft.com

src/bin/psql/tab-complete.c

index b64db82f029e43eacbf5731535371f1645ab1776..d7779925599b7419ac9605266972364585a98db9 100644 (file)
@@ -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",