@@ -3361,30 +3361,35 @@ match_previous_words(int pattern_id,
3361
3361
Matches ("COPY|\\copy" , MatchAny , "FROM" , "PROGRAM" , MatchAny ))
3362
3362
COMPLETE_WITH ("WITH (" , "WHERE" );
3363
3363
3364
- /* Complete COPY <sth> FROM [PROGRAM] filename WITH ( */
3365
- else if (Matches ("COPY|\\copy" , MatchAny , "FROM" , MatchAnyExcept ("PROGRAM" ), "WITH" , "(" ) ||
3366
- Matches ("COPY|\\copy" , MatchAny , "FROM" , "PROGRAM" , MatchAny , "WITH" , "(" ))
3367
- COMPLETE_WITH (Copy_from_options );
3368
-
3369
- /* Complete COPY <sth> TO [PROGRAM] filename WITH ( */
3370
- else if (Matches ("COPY|\\copy" , MatchAny , "TO" , MatchAnyExcept ("PROGRAM" ), "WITH" , "(" ) ||
3371
- Matches ("COPY|\\copy" , MatchAny , "TO" , "PROGRAM" , MatchAny , "WITH" , "(" ))
3372
- COMPLETE_WITH (Copy_to_options );
3373
-
3374
- /* Complete COPY <sth> FROM|TO [PROGRAM] <sth> WITH (FORMAT */
3375
- else if (Matches ("COPY|\\copy" , MatchAny , "FROM|TO" , MatchAnyExcept ("PROGRAM" ), "WITH" , "(" , "FORMAT" ) ||
3376
- Matches ("COPY|\\copy" , MatchAny , "FROM|TO" , "PROGRAM" , MatchAny , "WITH" , "(" , "FORMAT" ))
3377
- COMPLETE_WITH ("binary" , "csv" , "text" );
3378
-
3379
- /* Complete COPY <sth> FROM [PROGRAM] filename WITH (ON_ERROR */
3380
- else if (Matches ("COPY|\\copy" , MatchAny , "FROM" , MatchAnyExcept ("PROGRAM" ), "WITH" , "(" , "ON_ERROR" ) ||
3381
- Matches ("COPY|\\copy" , MatchAny , "FROM" , "PROGRAM" , MatchAny , "WITH" , "(" , "ON_ERROR" ))
3382
- COMPLETE_WITH ("stop" , "ignore" );
3383
-
3384
- /* Complete COPY <sth> FROM [PROGRAM] filename WITH (LOG_VERBOSITY */
3385
- else if (Matches ("COPY|\\copy" , MatchAny , "FROM" , MatchAnyExcept ("PROGRAM" ), "WITH" , "(" , "LOG_VERBOSITY" ) ||
3386
- Matches ("COPY|\\copy" , MatchAny , "FROM" , "PROGRAM" , MatchAny , "WITH" , "(" , "LOG_VERBOSITY" ))
3387
- COMPLETE_WITH ("silent" , "default" , "verbose" );
3364
+ /* Complete COPY <sth> FROM|TO [PROGRAM] filename WITH ( */
3365
+ else if (HeadMatches ("COPY|\\copy" , MatchAny , "FROM|TO" , MatchAnyExcept ("PROGRAM" ), "WITH" , "(" ) ||
3366
+ HeadMatches ("COPY|\\copy" , MatchAny , "FROM|TO" , "PROGRAM" , MatchAny , "WITH" , "(" ))
3367
+ {
3368
+ if (!HeadMatches ("COPY|\\copy" , MatchAny , "FROM|TO" , MatchAnyExcept ("PROGRAM" ), "WITH" , "(*)" ) &&
3369
+ !HeadMatches ("COPY|\\copy" , MatchAny , "FROM|TO" , "PROGRAM" , MatchAny , "WITH" , "(*)" ))
3370
+ {
3371
+ /* We're in an unfinished parenthesized option list. */
3372
+ if (ends_with (prev_wd , '(' ) || ends_with (prev_wd , ',' ))
3373
+ {
3374
+ if (HeadMatches ("COPY|\\copy" , MatchAny , "FROM" ))
3375
+ COMPLETE_WITH (Copy_from_options );
3376
+ else
3377
+ COMPLETE_WITH (Copy_to_options );
3378
+ }
3379
+
3380
+ /* Complete COPY <sth> FROM|TO filename WITH (FORMAT */
3381
+ else if (TailMatches ("FORMAT" ))
3382
+ COMPLETE_WITH ("binary" , "csv" , "text" );
3383
+
3384
+ /* Complete COPY <sth> FROM filename WITH (ON_ERROR */
3385
+ else if (TailMatches ("ON_ERROR" ))
3386
+ COMPLETE_WITH ("stop" , "ignore" );
3387
+
3388
+ /* Complete COPY <sth> FROM filename WITH (LOG_VERBOSITY */
3389
+ else if (TailMatches ("LOG_VERBOSITY" ))
3390
+ COMPLETE_WITH ("silent" , "default" , "verbose" );
3391
+ }
3392
+ }
3388
3393
3389
3394
/* Complete COPY <sth> FROM [PROGRAM] <sth> WITH (<options>) */
3390
3395
else if (Matches ("COPY|\\copy" , MatchAny , "FROM" , MatchAnyExcept ("PROGRAM" ), "WITH" , MatchAny ) ||
0 commit comments