aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2021-02-22 23:17:31 +1300
committerThomas Munro <tmunro@postgresql.org>2021-02-23 00:16:16 +1300
commit5bc09a74719dfeb6c4cebb311b81385c508459a8 (patch)
treecf7c2a16e5ef2e48efafd73a6bed93813cd067ee
parentbeb4480c853a60ec43bd3f1a71252890dd234f10 (diff)
downloadpostgresql-5bc09a74719dfeb6c4cebb311b81385c508459a8.tar.gz
postgresql-5bc09a74719dfeb6c4cebb311b81385c508459a8.zip
Tab-complete CREATE COLLATION.
Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/20210117215940.GE8560%40telsasoft.com
-rw-r--r--src/bin/psql/tab-complete.c26
1 files changed, 25 insertions, 1 deletions
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",