Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd67ab24

Browse files
author
Nikita Glukhov
committed
psql: add tab completion for compression methods and \dCM command
1 parente0a1f0f commitd67ab24

File tree

5 files changed

+108
-5
lines changed

5 files changed

+108
-5
lines changed

‎src/bin/psql/command.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,10 @@ exec_command_d(PsqlScanState scan_state, bool active_branch, const char *cmd)
736736
success=listConversions(pattern,show_verbose,show_system);
737737
break;
738738
case'C':
739-
success=listCasts(pattern,show_verbose);
739+
if (cmd[2]=='M')
740+
success=describeCompressionMethods(pattern,show_verbose);
741+
else
742+
success=listCasts(pattern,show_verbose);
740743
break;
741744
case'd':
742745
if (strncmp(cmd,"ddp",3)==0)

‎src/bin/psql/describe.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,68 @@ describeAccessMethods(const char *pattern, bool verbose)
198198
return true;
199199
}
200200

201+
/* \dA
202+
* Takes an optional regexp to select particular access methods
203+
*/
204+
bool
205+
describeCompressionMethods(constchar*pattern,boolverbose)
206+
{
207+
PQExpBufferDatabuf;
208+
PGresult*res;
209+
printQueryOptmyopt=pset.popt;
210+
staticconstbooltranslate_columns[]= {false, false, false};
211+
212+
if (pset.sversion<100000)
213+
{
214+
charsverbuf[32];
215+
216+
psql_error("The server (version %s) does not support compression methods.\n",
217+
formatPGVersionNumber(pset.sversion, false,
218+
sverbuf,sizeof(sverbuf)));
219+
return true;
220+
}
221+
222+
initPQExpBuffer(&buf);
223+
224+
printfPQExpBuffer(&buf,
225+
"SELECT cmname AS \"%s\"",
226+
gettext_noop("Name"));
227+
228+
if (verbose)
229+
{
230+
appendPQExpBuffer(&buf,
231+
",\n cmhandler AS \"%s\",\n"
232+
" pg_catalog.obj_description(oid, 'pg_compression') AS \"%s\"",
233+
gettext_noop("Handler"),
234+
gettext_noop("Description"));
235+
}
236+
237+
appendPQExpBufferStr(&buf,
238+
"\nFROM pg_catalog.pg_compression\n");
239+
240+
processSQLNamePattern(pset.db,&buf,pattern, false, false,
241+
NULL,"cmname",NULL,
242+
NULL);
243+
244+
appendPQExpBufferStr(&buf,"ORDER BY 1;");
245+
246+
res=PSQLexec(buf.data);
247+
termPQExpBuffer(&buf);
248+
if (!res)
249+
return false;
250+
251+
myopt.nullPrint=NULL;
252+
myopt.title=_("List of compression methods");
253+
myopt.translate_header= true;
254+
myopt.translate_columns=translate_columns;
255+
myopt.n_translate_columns=lengthof(translate_columns);
256+
257+
printQuery(res,&myopt,pset.queryFout, false,pset.logfile);
258+
259+
PQclear(res);
260+
return true;
261+
}
262+
201263
/* \db
202264
* Takes an optional regexp to select particular tablespaces
203265
*/

‎src/bin/psql/describe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ extern bool describeAccessMethods(const char *pattern, bool verbose);
1818
/* \db */
1919
externbooldescribeTablespaces(constchar*pattern,boolverbose);
2020

21+
/* \dCM */
22+
externbooldescribeCompressionMethods(constchar*pattern,boolverbose);
23+
2124
/* \df, \dfa, \dfn, \dft, \dfw, etc. */
2225
externbooldescribeFunctions(constchar*functypes,constchar*pattern,boolverbose,boolshowSystem);
2326

‎src/bin/psql/help.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ slashUsage(unsigned short int pager)
226226
fprintf(output,_(" \\db[+] [PATTERN] list tablespaces\n"));
227227
fprintf(output,_(" \\dc[S+] [PATTERN] list conversions\n"));
228228
fprintf(output,_(" \\dC[+] [PATTERN] list casts\n"));
229+
fprintf(output,_(" \\dCM[+] [PATTERN] list compression methods\n"));
229230
fprintf(output,_(" \\dd[S] [PATTERN] show object descriptions not displayed elsewhere\n"));
230231
fprintf(output,_(" \\ddp [PATTERN] list default privileges\n"));
231232
fprintf(output,_(" \\dD[S+] [PATTERN] list domains\n"));

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

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,11 @@ static const SchemaQuery Query_for_list_of_matviews = {
874874
" AND d.datname = pg_catalog.current_database() "\
875875
" AND s.subdbid = d.oid"
876876

877+
#defineQuery_for_list_of_compression_methods \
878+
" SELECT pg_catalog.quote_ident(cmname) "\
879+
" FROM pg_catalog.pg_compression "\
880+
" WHERE substring(pg_catalog.quote_ident(cmname),1,%d)='%s'"
881+
877882
/* the silly-looking length condition is just to eat up the current word */
878883
#defineQuery_for_list_of_arguments \
879884
"SELECT pg_catalog.oidvectortypes(proargtypes)||')' "\
@@ -996,6 +1001,7 @@ static const pgsql_thing_t words_after_create[] = {
9961001
* CREATE CONSTRAINT TRIGGER is not supported here because it is designed
9971002
* to be used only by pg_dump.
9981003
*/
1004+
{"COMPRESSION METHOD",NULL,NULL},
9991005
{"CONFIGURATION",Query_for_list_of_ts_configurations,NULL,THING_NO_SHOW},
10001006
{"CONVERSION","SELECT pg_catalog.quote_ident(conname) FROM pg_catalog.pg_conversion WHERE substring(pg_catalog.quote_ident(conname),1,%d)='%s'"},
10011007
{"DATABASE",Query_for_list_of_databases},
@@ -1404,8 +1410,8 @@ psql_completion(const char *text, int start, int end)
14041410
staticconstchar*constbackslash_commands[]= {
14051411
"\\a","\\connect","\\conninfo","\\C","\\cd","\\copy",
14061412
"\\copyright","\\crosstabview",
1407-
"\\d","\\da","\\dA","\\db","\\dc","\\dC","\\dd","\\ddp","\\dD",
1408-
"\\des","\\det","\\deu","\\dew","\\dE","\\df",
1413+
"\\d","\\da","\\dA","\\db","\\dc","\\dC","\\dCM","\\dd","\\ddp",
1414+
"\\dD","\\des","\\det","\\deu","\\dew","\\dE","\\df",
14091415
"\\dF","\\dFd","\\dFp","\\dFt","\\dg","\\di","\\dl","\\dL",
14101416
"\\dm","\\dn","\\do","\\dO","\\dp","\\drds","\\ds","\\dS",
14111417
"\\dt","\\dT","\\dv","\\du","\\dx","\\dy",
@@ -1906,11 +1912,17 @@ psql_completion(const char *text, int start, int end)
19061912
/* ALTER TABLE ALTER [COLUMN] <foo> SET */
19071913
elseif (Matches7("ALTER","TABLE",MatchAny,"ALTER","COLUMN",MatchAny,"SET")||
19081914
Matches6("ALTER","TABLE",MatchAny,"ALTER",MatchAny,"SET"))
1909-
COMPLETE_WITH_LIST5("(","DEFAULT","NOT NULL","STATISTICS","STORAGE");
1915+
COMPLETE_WITH_LIST6("(","COMPRESSED","DEFAULT","NOT NULL","STATISTICS","STORAGE");
19101916
/* ALTER TABLE ALTER [COLUMN] <foo> SET ( */
19111917
elseif (Matches8("ALTER","TABLE",MatchAny,"ALTER","COLUMN",MatchAny,"SET","(")||
19121918
Matches7("ALTER","TABLE",MatchAny,"ALTER",MatchAny,"SET","("))
19131919
COMPLETE_WITH_LIST2("n_distinct","n_distinct_inherited");
1920+
elseif (Matches8("ALTER","TABLE",MatchAny,"ALTER","COLUMN",MatchAny,"SET","COMPRESSED")||
1921+
Matches7("ALTER","TABLE",MatchAny,"ALTER",MatchAny,"SET","COMPRESSED"))
1922+
COMPLETE_WITH_QUERY(Query_for_list_of_compression_methods);
1923+
elseif (Matches9("ALTER","TABLE",MatchAny,"ALTER","COLUMN",MatchAny,"SET","COMPRESSED",MatchAny)||
1924+
Matches8("ALTER","TABLE",MatchAny,"ALTER",MatchAny,"SET","COMPRESSED",MatchAny))
1925+
COMPLETE_WITH_CONST("WITH (");
19141926
/* ALTER TABLE ALTER [COLUMN] <foo> SET STORAGE */
19151927
elseif (Matches8("ALTER","TABLE",MatchAny,"ALTER","COLUMN",MatchAny,"SET","STORAGE")||
19161928
Matches7("ALTER","TABLE",MatchAny,"ALTER",MatchAny,"SET","STORAGE"))
@@ -2125,12 +2137,14 @@ psql_completion(const char *text, int start, int end)
21252137
"SERVER","INDEX","LANGUAGE","POLICY","PUBLICATION","RULE","SCHEMA","SEQUENCE","SUBSCRIPTION",
21262138
"TABLE","TYPE","VIEW","MATERIALIZED VIEW","COLUMN","AGGREGATE","FUNCTION",
21272139
"OPERATOR","TRIGGER","CONSTRAINT","DOMAIN","LARGE OBJECT",
2128-
"TABLESPACE","TEXT SEARCH","ROLE",NULL};
2140+
"TABLESPACE","TEXT SEARCH","ROLE","COMPRESSION METHOD",NULL};
21292141

21302142
COMPLETE_WITH_LIST(list_COMMENT);
21312143
}
21322144
elseif (Matches4("COMMENT","ON","ACCESS","METHOD"))
21332145
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
2146+
elseif (Matches4("COMMENT","ON","COMPRESSION","METHOD"))
2147+
COMPLETE_WITH_QUERY(Query_for_list_of_compression_methods);
21342148
elseif (Matches3("COMMENT","ON","FOREIGN"))
21352149
COMPLETE_WITH_LIST2("DATA WRAPPER","TABLE");
21362150
elseif (Matches4("COMMENT","ON","TEXT","SEARCH"))
@@ -2203,6 +2217,17 @@ psql_completion(const char *text, int start, int end)
22032217
elseif (Matches6("CREATE","ACCESS","METHOD",MatchAny,"TYPE",MatchAny))
22042218
COMPLETE_WITH_CONST("HANDLER");
22052219

2220+
/* CREATE COMPRESSION METHOD */
2221+
/* Complete "CREATE COMPRESSION METHOD <name>" */
2222+
elseif (Matches4("CREATE","COMPRESSION","METHOD",MatchAny))
2223+
COMPLETE_WITH_CONST("FOR");
2224+
/* Complete "CREATE COMPRESSION METHOD <name> FOR" */
2225+
elseif (Matches5("CREATE","COMPRESSION","METHOD",MatchAny,"FOR"))
2226+
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_datatypes,NULL);
2227+
/* Complete "CREATE COMPRESSION METHOD <name> FOR <type>" */
2228+
elseif (Matches6("CREATE","COMPRESSION","METHOD",MatchAny,"FOR",MatchAny))
2229+
COMPLETE_WITH_CONST("HANDLER");
2230+
22062231
/* CREATE DATABASE */
22072232
elseif (Matches3("CREATE","DATABASE",MatchAny))
22082233
COMPLETE_WITH_LIST9("OWNER","TEMPLATE","ENCODING","TABLESPACE",
@@ -2603,6 +2628,7 @@ psql_completion(const char *text, int start, int end)
26032628
Matches4("DROP","ACCESS","METHOD",MatchAny)||
26042629
(Matches4("DROP","AGGREGATE|FUNCTION",MatchAny,MatchAny)&&
26052630
ends_with(prev_wd,')'))||
2631+
Matches4("DROP","COMPRESSION","METHOD",MatchAny)||
26062632
Matches4("DROP","EVENT","TRIGGER",MatchAny)||
26072633
Matches5("DROP","FOREIGN","DATA","WRAPPER",MatchAny)||
26082634
Matches4("DROP","FOREIGN","TABLE",MatchAny)||
@@ -2695,6 +2721,12 @@ psql_completion(const char *text, int start, int end)
26952721
elseif (Matches3("DROP","SUBSCRIPTION",MatchAny))
26962722
COMPLETE_WITH_LIST2("DROP SLOT","NODROP SLOT");
26972723

2724+
/* DROP COMPRESSION METHOD */
2725+
elseif (Matches2("DROP","COMPRESSION"))
2726+
COMPLETE_WITH_CONST("METHOD");
2727+
elseif (Matches3("DROP","COMPRESSION","METHOD"))
2728+
COMPLETE_WITH_QUERY(Query_for_list_of_compression_methods);
2729+
26982730
/* EXECUTE */
26992731
elseif (Matches1("EXECUTE"))
27002732
COMPLETE_WITH_QUERY(Query_for_list_of_prepared_statements);
@@ -3325,6 +3357,8 @@ psql_completion(const char *text, int start, int end)
33253357
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
33263358
elseif (TailMatchesCS1("\\db*"))
33273359
COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
3360+
elseif (TailMatchesCS1("\\dCM*"))
3361+
COMPLETE_WITH_QUERY(Query_for_list_of_compression_methods);
33283362
elseif (TailMatchesCS1("\\dD*"))
33293363
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains,NULL);
33303364
elseif (TailMatchesCS1("\\des*"))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp