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

Commit0240a00

Browse files
committed
Fix some issues and improve psql completion for access methods
The following issues have been spotted:- CREATE INDEX .. USING suggests both index and table AMs, but it shouldconsider only index AMs.- CREATE TABLE .. USING has no completion support. USING was not beingincluded in the completion list where it should, and follow-upsuggestions for table AMs have been missing as well.- CREATE ACCESS METHOD .. TYPE suggests only INDEX, with TABLE missing.Author: Michael PaquierDiscussion:https://postgr.es/m/20190601191007.GC1905@paquier.xyz
1 parentf4755a2 commit0240a00

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include<ctype.h>
4343

44+
#include"catalog/pg_am_d.h"
4445
#include"catalog/pg_class_d.h"
4546

4647
#include"libpq-fe.h"
@@ -824,6 +825,18 @@ static const SchemaQuery Query_for_list_of_statistics = {
824825
" FROM pg_catalog.pg_am "\
825826
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s'"
826827

828+
#defineQuery_for_list_of_index_access_methods \
829+
" SELECT pg_catalog.quote_ident(amname) "\
830+
" FROM pg_catalog.pg_am "\
831+
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s' AND "\
832+
" amtype=" CppAsString2(AMTYPE_INDEX)
833+
834+
#defineQuery_for_list_of_table_access_methods \
835+
" SELECT pg_catalog.quote_ident(amname) "\
836+
" FROM pg_catalog.pg_am "\
837+
" WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s' AND "\
838+
" amtype=" CppAsString2(AMTYPE_TABLE)
839+
827840
/* the silly-looking length condition is just to eat up the current word */
828841
#defineQuery_for_list_of_arguments \
829842
"SELECT pg_catalog.oidvectortypes(proargtypes)||')' "\
@@ -2234,7 +2247,7 @@ psql_completion(const char *text, int start, int end)
22342247
COMPLETE_WITH("TYPE");
22352248
/* Complete "CREATE ACCESS METHOD <name> TYPE" */
22362249
elseif (Matches("CREATE","ACCESS","METHOD",MatchAny,"TYPE"))
2237-
COMPLETE_WITH("INDEX");
2250+
COMPLETE_WITH("INDEX","TABLE");
22382251
/* Complete "CREATE ACCESS METHOD <name> TYPE <type>" */
22392252
elseif (Matches("CREATE","ACCESS","METHOD",MatchAny,"TYPE",MatchAny))
22402253
COMPLETE_WITH("HANDLER");
@@ -2322,7 +2335,7 @@ psql_completion(const char *text, int start, int end)
23222335
elseif (TailMatches("INDEX",MatchAny,MatchAny,"ON",MatchAny,"USING")||
23232336
TailMatches("INDEX",MatchAny,"ON",MatchAny,"USING")||
23242337
TailMatches("INDEX","ON",MatchAny,"USING"))
2325-
COMPLETE_WITH_QUERY(Query_for_list_of_access_methods);
2338+
COMPLETE_WITH_QUERY(Query_for_list_of_index_access_methods);
23262339
elseif (TailMatches("ON",MatchAny,"USING",MatchAny)&&
23272340
!TailMatches("POLICY",MatchAny,MatchAny,MatchAny,MatchAny,MatchAny)&&
23282341
!TailMatches("FOR",MatchAny,MatchAny,MatchAny))
@@ -2490,10 +2503,14 @@ psql_completion(const char *text, int start, int end)
24902503
/* Complete CREATE TABLE name (...) with supported options */
24912504
elseif (TailMatches("CREATE","TABLE",MatchAny,"(*)")||
24922505
TailMatches("CREATE","UNLOGGED","TABLE",MatchAny,"(*)"))
2493-
COMPLETE_WITH("INHERITS (","PARTITION BY","TABLESPACE","WITH (");
2506+
COMPLETE_WITH("INHERITS (","PARTITION BY","USING","TABLESPACE","WITH (");
24942507
elseif (TailMatches("CREATE","TEMP|TEMPORARY","TABLE",MatchAny,"(*)"))
24952508
COMPLETE_WITH("INHERITS (","ON COMMIT","PARTITION BY",
24962509
"TABLESPACE","WITH (");
2510+
/* Complete CREATE TABLE (...) USING with table access methods */
2511+
elseif (TailMatches("CREATE","TABLE",MatchAny,"(*)","USING")||
2512+
TailMatches("CREATE","TEMP|TEMPORARY|UNLOGGED","TABLE",MatchAny,"(*)","USING"))
2513+
COMPLETE_WITH_QUERY(Query_for_list_of_table_access_methods);
24972514
/* Complete CREATE TABLE (...) WITH with storage parameters */
24982515
elseif (TailMatches("CREATE","TABLE",MatchAny,"(*)","WITH","(")||
24992516
TailMatches("CREATE","TEMP|TEMPORARY|UNLOGGED","TABLE",MatchAny,"(*)","WITH","("))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp