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

Commit074add6

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 parent4b85f20 commit074add6

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
@@ -3532,8 +3532,13 @@ psql_completion(const char *text, int start, int end)
35323532
elseif (HeadMatches2("ALTER","DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER")&&
35333533
TailMatches2("SET",MatchAny))
35343534
COMPLETE_WITH_LIST2("FROM CURRENT","TO");
3535-
/* Suggest possible variable values */
3536-
elseif (TailMatches3("SET",MatchAny,"TO|="))
3535+
3536+
/*
3537+
* Suggest possible variable values in SET variable TO|=, along with the
3538+
* preceding ALTER syntaxes.
3539+
*/
3540+
elseif (TailMatches3("SET",MatchAny,"TO|=")&&
3541+
!TailMatches5("UPDATE",MatchAny,"SET",MatchAny,"TO|="))
35373542
{
35383543
/* special cased code for individual GUCs */
35393544
if (TailMatches2("DateStyle","TO|="))
@@ -3556,21 +3561,29 @@ psql_completion(const char *text, int start, int end)
35563561
/* generic, type based, GUC support */
35573562
char*guctype=get_guctype(prev2_wd);
35583563

3559-
if (guctype&&strcmp(guctype,"enum")==0)
3564+
/*
3565+
* Note: if we don't recognize the GUC name, it's important to not
3566+
* offer any completions, as most likely we've misinterpreted the
3567+
* context and this isn't a GUC-setting command at all.
3568+
*/
3569+
if (guctype)
35603570
{
3561-
charquerybuf[1024];
3571+
if (strcmp(guctype,"enum")==0)
3572+
{
3573+
charquerybuf[1024];
35623574

3563-
snprintf(querybuf,sizeof(querybuf),Query_for_enum,prev2_wd);
3564-
COMPLETE_WITH_QUERY(querybuf);
3565-
}
3566-
elseif (guctype&&strcmp(guctype,"bool")==0)
3567-
COMPLETE_WITH_LIST9("on","off","true","false","yes","no",
3568-
"1","0","DEFAULT");
3569-
else
3570-
COMPLETE_WITH_CONST("DEFAULT");
3575+
snprintf(querybuf,sizeof(querybuf),
3576+
Query_for_enum,prev2_wd);
3577+
COMPLETE_WITH_QUERY(querybuf);
3578+
}
3579+
elseif (strcmp(guctype,"bool")==0)
3580+
COMPLETE_WITH_LIST9("on","off","true","false",
3581+
"yes","no","1","0","DEFAULT");
3582+
else
3583+
COMPLETE_WITH_CONST("DEFAULT");
35713584

3572-
if (guctype)
35733585
free(guctype);
3586+
}
35743587
}
35753588
}
35763589

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp