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

Commitc273d9d

Browse files
committed
Rework tab completion of COPY and \copy in psql
This corrects and simplifies $subject in a number of ways:- Remove from the completion the pre-9.0 grammar still supported forcompatibility purposes. This simplifies the code, and allows to extendit more easily with new patterns.- Add completion for the options of FORMAT within a WITH clause.- Complete WHERE and WITH clauses correctly depending on if TO or FROMare used, WHERE being only available with COPY FROM.Author: Vignesh C, Michael PaquierReviewed-by: Ahsan HadiDiscussion:https://postgr.es/m/CALDaNm3zWr=OmxeNqOqfT=uZTSdam_j-gkX94CL8eTNfgUtf6A@mail.gmail.com
1 parenta4faef8 commitc273d9d

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

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

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,19 +2316,14 @@ psql_completion(const char *text, int start, int end)
23162316
elseif (Matches("COPY|\\copy"))
23172317
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,
23182318
" UNION ALL SELECT '('");
2319-
/* If we have COPY BINARY, complete with list of tables */
2320-
elseif (Matches("COPY","BINARY"))
2321-
COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables,NULL);
2322-
/* If we have COPY (, complete it with legal commands */
2319+
/* Complete COPY ( with legal query commands */
23232320
elseif (Matches("COPY|\\copy","("))
23242321
COMPLETE_WITH("SELECT","TABLE","VALUES","INSERT","UPDATE","DELETE","WITH");
2325-
/* If we have COPY [BINARY] <sth>, complete it with "TO" or "FROM" */
2326-
elseif (Matches("COPY|\\copy",MatchAny)||
2327-
Matches("COPY","BINARY",MatchAny))
2322+
/* Complete COPY <sth> */
2323+
elseif (Matches("COPY|\\copy",MatchAny))
23282324
COMPLETE_WITH("FROM","TO");
2329-
/* If we have COPY [BINARY] <sth> FROM|TO, complete with filename */
2330-
elseif (Matches("COPY",MatchAny,"FROM|TO")||
2331-
Matches("COPY","BINARY",MatchAny,"FROM|TO"))
2325+
/* Complete COPY <sth> FROM|TO with filename */
2326+
elseif (Matches("COPY",MatchAny,"FROM|TO"))
23322327
{
23332328
completion_charp="";
23342329
completion_force_quote= true;/* COPY requires quoted filename */
@@ -2340,17 +2335,28 @@ psql_completion(const char *text, int start, int end)
23402335
completion_force_quote= false;
23412336
matches=rl_completion_matches(text,complete_from_files);
23422337
}
2343-
/* Offer options after COPY [BINARY] <sth> FROM|TO filename */
2344-
elseif (Matches("COPY|\\copy",MatchAny,"FROM|TO",MatchAny)||
2345-
Matches("COPY","BINARY",MatchAny,"FROM|TO",MatchAny))
2346-
COMPLETE_WITH("BINARY","DELIMITER","NULL","CSV",
2347-
"ENCODING");
2348-
2349-
/* Offer options after COPY [BINARY] <sth> FROM|TO filename CSV */
2350-
elseif (Matches("COPY|\\copy",MatchAny,"FROM|TO",MatchAny,"CSV")||
2351-
Matches("COPY","BINARY",MatchAny,"FROM|TO",MatchAny,"CSV"))
2352-
COMPLETE_WITH("HEADER","QUOTE","ESCAPE","FORCE QUOTE",
2353-
"FORCE NOT NULL");
2338+
2339+
/* Complete COPY <sth> TO <sth> */
2340+
elseif (Matches("COPY|\\copy",MatchAny,"TO",MatchAny))
2341+
COMPLETE_WITH("WITH (");
2342+
2343+
/* Complete COPY <sth> FROM <sth> */
2344+
elseif (Matches("COPY|\\copy",MatchAny,"FROM",MatchAny))
2345+
COMPLETE_WITH("WITH (","WHERE");
2346+
2347+
/* Complete COPY <sth> FROM|TO filename WITH ( */
2348+
elseif (Matches("COPY|\\copy",MatchAny,"FROM|TO",MatchAny,"WITH","("))
2349+
COMPLETE_WITH("FORMAT","FREEZE","DELIMITER","NULL",
2350+
"HEADER","QUOTE","ESCAPE","FORCE_QUOTE",
2351+
"FORCE_NOT_NULL","FORCE_NULL","ENCODING");
2352+
2353+
/* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
2354+
elseif (Matches("COPY|\\copy",MatchAny,"FROM|TO",MatchAny,"WITH","(","FORMAT"))
2355+
COMPLETE_WITH("binary","csv","text");
2356+
2357+
/* Complete COPY <sth> FROM <sth> WITH (<options>) */
2358+
elseif (Matches("COPY|\\copy",MatchAny,"FROM",MatchAny,"WITH",MatchAny))
2359+
COMPLETE_WITH("WHERE");
23542360

23552361
/* CREATE ACCESS METHOD */
23562362
/* Complete "CREATE ACCESS METHOD <name>" */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp