Skip to content

Commit 2955c2b

Browse files
committed
Re-allow custom GUC names that have more than two components.
Commit 3db826b disallowed this case, but it turns out that some people are depending on it. Since the core grammar has allowed it since 3dc37cd, it seems like this code should fall in line. Per bug #17045 from Robert Sosinski. Discussion: https://postgr.es/m/17045-6a4a9f0d1513f72b@postgresql.org
1 parent 8e03eb9 commit 2955c2b

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

src/backend/utils/misc/guc.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -5368,13 +5368,14 @@ add_guc_variable(struct config_generic *var, int elevel)
53685368
/*
53695369
* Decide whether a proposed custom variable name is allowed.
53705370
*
5371-
* It must be "identifier.identifier", where the rules for what is an
5372-
* identifier agree with scan.l.
5371+
* It must be two or more identifiers separated by dots, where the rules
5372+
* for what is an identifier agree with scan.l. (If you change this rule,
5373+
* adjust the errdetail in find_option().)
53735374
*/
53745375
static bool
53755376
valid_custom_variable_name(const char *name)
53765377
{
5377-
int num_sep = 0;
5378+
bool saw_sep = false;
53785379
bool name_start = true;
53795380

53805381
for (const char *p = name; *p; p++)
@@ -5383,7 +5384,7 @@ valid_custom_variable_name(const char *name)
53835384
{
53845385
if (name_start)
53855386
return false; /* empty name component */
5386-
num_sep++;
5387+
saw_sep = true;
53875388
name_start = true;
53885389
}
53895390
else if (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -5400,8 +5401,8 @@ valid_custom_variable_name(const char *name)
54005401
}
54015402
if (name_start)
54025403
return false; /* empty name component */
5403-
/* OK if we had exactly one separator */
5404-
return (num_sep == 1);
5404+
/* OK if we found at least one separator */
5405+
return saw_sep;
54055406
}
54065407

54075408
/*
@@ -5516,7 +5517,7 @@ find_option(const char *name, bool create_placeholders, bool skip_errors,
55165517
(errcode(ERRCODE_INVALID_NAME),
55175518
errmsg("invalid configuration parameter name \"%s\"",
55185519
name),
5519-
errdetail("Custom parameter names must be of the form \"identifier.identifier\".")));
5520+
errdetail("Custom parameter names must be two or more simple identifiers separated by dots.")));
55205521
return NULL;
55215522
}
55225523
}

src/test/regress/expected/guc.out

+18-2
Original file line numberDiff line numberDiff line change
@@ -515,21 +515,37 @@ SET no_such_variable TO 42;
515515
ERROR: unrecognized configuration parameter "no_such_variable"
516516
-- Test "custom" GUCs created on the fly (which aren't really an
517517
-- intended feature, but many people use them).
518+
SHOW custom.my_guc; -- error, not known yet
519+
ERROR: unrecognized configuration parameter "custom.my_guc"
518520
SET custom.my_guc = 42;
519521
SHOW custom.my_guc;
520522
custom.my_guc
521523
---------------
522524
42
523525
(1 row)
524526

527+
RESET custom.my_guc; -- this makes it go to empty, not become unknown again
528+
SHOW custom.my_guc;
529+
custom.my_guc
530+
---------------
531+
532+
(1 row)
533+
534+
SET custom.my.qualified.guc = 'foo';
535+
SHOW custom.my.qualified.guc;
536+
custom.my.qualified.guc
537+
-------------------------
538+
foo
539+
(1 row)
540+
525541
SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name
526542
ERROR: invalid configuration parameter name "custom.bad-guc"
527-
DETAIL: Custom parameter names must be of the form "identifier.identifier".
543+
DETAIL: Custom parameter names must be two or more simple identifiers separated by dots.
528544
SHOW custom."bad-guc";
529545
ERROR: unrecognized configuration parameter "custom.bad-guc"
530546
SET special."weird name" = 'foo'; -- could be allowed, but we choose not to
531547
ERROR: invalid configuration parameter name "special.weird name"
532-
DETAIL: Custom parameter names must be of the form "identifier.identifier".
548+
DETAIL: Custom parameter names must be two or more simple identifiers separated by dots.
533549
SHOW special."weird name";
534550
ERROR: unrecognized configuration parameter "special.weird name"
535551
--

src/test/regress/sql/guc.sql

+5
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,13 @@ SET no_such_variable TO 42;
151151

152152
-- Test "custom" GUCs created on the fly (which aren't really an
153153
-- intended feature, but many people use them).
154+
SHOW custom.my_guc; -- error, not known yet
154155
SET custom.my_guc = 42;
155156
SHOW custom.my_guc;
157+
RESET custom.my_guc; -- this makes it go to empty, not become unknown again
158+
SHOW custom.my_guc;
159+
SET custom.my.qualified.guc = 'foo';
160+
SHOW custom.my.qualified.guc;
156161
SET custom."bad-guc" = 42; -- disallowed because -c cannot set this name
157162
SHOW custom."bad-guc";
158163
SET special."weird name" = 'foo'; -- could be allowed, but we choose not to

0 commit comments

Comments
 (0)