Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5bc09a7

Browse filesBrowse files
committed
Tab-complete CREATE COLLATION.
Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/20210117215940.GE8560%40telsasoft.com
1 parent beb4480 commit 5bc09a7
Copy full SHA for 5bc09a7

File tree

Expand file treeCollapse file tree

1 file changed

+25
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-1
lines changed

‎src/bin/psql/tab-complete.c

Copy file name to clipboardExpand all lines: src/bin/psql/tab-complete.c
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,14 @@ static const SchemaQuery Query_for_list_of_statistics = {
609609
.result = "pg_catalog.quote_ident(s.stxname)",
610610
};
611611

612+
static const SchemaQuery Query_for_list_of_collations = {
613+
.catname = "pg_catalog.pg_collation c",
614+
.selcondition = "c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))",
615+
.viscondition = "pg_catalog.pg_collation_is_visible(c.oid)",
616+
.namespace = "c.collnamespace",
617+
.result = "pg_catalog.quote_ident(c.collname)",
618+
};
619+
612620

613621
/*
614622
* Queries to get lists of names of various kinds of things, possibly
@@ -1031,7 +1039,7 @@ static const pgsql_thing_t words_after_create[] = {
10311039
{"AGGREGATE", NULL, NULL, Query_for_list_of_aggregates},
10321040
{"CAST", NULL, NULL, NULL}, /* Casts have complex structures for names, so
10331041
* skip it */
1034-
{"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'"},
1042+
{"COLLATION", NULL, NULL, &Query_for_list_of_collations},
10351043

10361044
/*
10371045
* CREATE CONSTRAINT TRIGGER is not supported here because it is designed
@@ -2433,6 +2441,22 @@ psql_completion(const char *text, int start, int end)
24332441
else if (Matches("CREATE", "ACCESS", "METHOD", MatchAny, "TYPE", MatchAny))
24342442
COMPLETE_WITH("HANDLER");
24352443

2444+
/* CREATE COLLATION */
2445+
else if (Matches("CREATE", "COLLATION", MatchAny))
2446+
COMPLETE_WITH("(", "FROM");
2447+
else if (Matches("CREATE", "COLLATION", MatchAny, "FROM"))
2448+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_collations, NULL);
2449+
else if (HeadMatches("CREATE", "COLLATION", MatchAny, "(*"))
2450+
{
2451+
if (TailMatches("(|*,"))
2452+
COMPLETE_WITH("LOCALE =", "LC_COLLATE =", "LC_CTYPE =",
2453+
"PROVIDER =", "DETERMINISTIC =");
2454+
else if (TailMatches("PROVIDER", "="))
2455+
COMPLETE_WITH("libc", "icu");
2456+
else if (TailMatches("DETERMINISTIC", "="))
2457+
COMPLETE_WITH("true", "false");
2458+
}
2459+
24362460
/* CREATE DATABASE */
24372461
else if (Matches("CREATE", "DATABASE", MatchAny))
24382462
COMPLETE_WITH("OWNER", "TEMPLATE", "ENCODING", "TABLESPACE",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.