Skip to content

Commit 5bc09a7

Browse 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

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/bin/psql/tab-complete.c

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy