Skip to content

Commit 4f3648d

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-setting command. If we have "SET var =" but the "var" is not a known GUC variable, don't offer any completions. The most likely explanation is that we'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 exists further back, but before 9.6 the code looks very different and it doesn'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 parent d4b090f commit 4f3648d

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
else if (HeadMatches("ALTER", "DATABASE|FUNCTION|PROCEDURE|ROLE|ROUTINE|USER") &&
33633363
TailMatches("SET", MatchAny))
33643364
COMPLETE_WITH("FROM CURRENT", "TO");
3365-
/* Suggest possible variable values */
3366-
else if (TailMatches("SET", MatchAny, "TO|="))
3365+
3366+
/*
3367+
* Suggest possible variable values in SET variable TO|=, along with the
3368+
* preceding ALTER syntaxes.
3369+
*/
3370+
else if (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-
char querybuf[1024];
3396+
if (strcmp(guctype, "enum") == 0)
3397+
{
3398+
char querybuf[1024];
33873399

3388-
snprintf(querybuf, sizeof(querybuf), Query_for_enum, prev2_wd);
3389-
COMPLETE_WITH_QUERY(querybuf);
3390-
}
3391-
else if (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+
else if (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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy