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

Commit0ec3e13

Browse files
committed
Fix tab completion of "SET variable TO|=" to not offer bogus completions.
Don't think that the context "UPDATE tab SET var =" is a GUC-settingcommand.If we have "SET var =" but the "var" is not a known GUC variable,don't offer any completions. The most likely explanation is thatwe've misparsed the context and it's not really a GUC-setting command.Per gripe from Ken Tanzer. Back-patch to 9.6. The issue existsfurther back, but before 9.6 the code looks very different and itdoesn't actually know whether the "var" name matches anything,so I desisted from trying to fix it.Discussion:https://postgr.es/m/CAD3a31XpXzrZA9TT3BqLSHghdTK+=cXjNCE+oL2Zn4+oWoc=qA@mail.gmail.com
1 parent4d6603f commit0ec3e13

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,8 +3362,13 @@ psql_completion(const char *text, int start, int end)
33623362
elseif (HeadMatches("ALTER","DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER")&&
33633363
TailMatches("SET",MatchAny))
33643364
COMPLETE_WITH("FROM CURRENT","TO");
3365-
/* Suggest possible variable values */
3366-
elseif (TailMatches("SET",MatchAny,"TO|="))
3365+
3366+
/*
3367+
* Suggest possible variable values in SET variable TO|=, along with the
3368+
* preceding ALTER syntaxes.
3369+
*/
3370+
elseif (TailMatches("SET",MatchAny,"TO|=")&&
3371+
!TailMatches("UPDATE",MatchAny,"SET",MatchAny,"TO|="))
33673372
{
33683373
/* special cased code for individual GUCs */
33693374
if (TailMatches("DateStyle","TO|="))
@@ -3381,21 +3386,29 @@ psql_completion(const char *text, int start, int end)
33813386
/* generic, type based, GUC support */
33823387
char*guctype=get_guctype(prev2_wd);
33833388

3384-
if (guctype&&strcmp(guctype,"enum")==0)
3389+
/*
3390+
* Note: if we don't recognize the GUC name, it's important to not
3391+
* offer any completions, as most likely we've misinterpreted the
3392+
* context and this isn't a GUC-setting command at all.
3393+
*/
3394+
if (guctype)
33853395
{
3386-
charquerybuf[1024];
3396+
if (strcmp(guctype,"enum")==0)
3397+
{
3398+
charquerybuf[1024];
33873399

3388-
snprintf(querybuf,sizeof(querybuf),Query_for_enum,prev2_wd);
3389-
COMPLETE_WITH_QUERY(querybuf);
3390-
}
3391-
elseif (guctype&&strcmp(guctype,"bool")==0)
3392-
COMPLETE_WITH("on","off","true","false","yes","no",
3393-
"1","0","DEFAULT");
3394-
else
3395-
COMPLETE_WITH("DEFAULT");
3400+
snprintf(querybuf,sizeof(querybuf),
3401+
Query_for_enum,prev2_wd);
3402+
COMPLETE_WITH_QUERY(querybuf);
3403+
}
3404+
elseif (strcmp(guctype,"bool")==0)
3405+
COMPLETE_WITH("on","off","true","false","yes","no",
3406+
"1","0","DEFAULT");
3407+
else
3408+
COMPLETE_WITH("DEFAULT");
33963409

3397-
if (guctype)
33983410
free(guctype);
3411+
}
33993412
}
34003413
}
34013414

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp