postgres=# SELECT version(); version ------------------------------------------------------------------------------------------------------ PostgreSQL 13.6on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit (1row)
postgres=# SET custom._my_guc =50; SET postgres=# SHOW custom._my_guc; custom._my_guc ---------------- 50 (1row)
接着,我们在 PG14 上面来进行测试。
1 2 3 4 5 6 7 8 9
postgres=# SELECT version(); version ------------------------------------------------------------------------------------------------------ PostgreSQL 14.2on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit (1row)
postgres=# SET custom._my_guc =50; ERROR: invalid configuration parameter name "custom._my_guc" DETAIL: Custom parameter names must be two or more simple identifiers separated by dots.
if (create_placeholders) { /* * Check if the name is valid, and if so, add a placeholder. If it * doesn't contain a separator, don't assume that it was meant to be a * placeholder. */ if (strchr(name, GUC_QUALIFIER_SEPARATOR) != NULL) { if (valid_custom_variable_name(name)) return add_placeholder_variable(name, elevel); /* A special error message seems desirable here */ if (!skip_errors) ereport(elevel, (errcode(ERRCODE_INVALID_NAME), errmsg("invalid configuration parameter name \"%s\"", name), errdetail("Custom parameter names must be two or more simple identifiers separated by dots."))); returnNULL; } }
/* * Decide whether a proposed custom variable name is allowed. * * It must be two or more identifiers separated by dots, where the rules * for what is an identifier agree with scan.l. (If you change this rule, * adjust the errdetail in find_option().) */ staticbool valid_custom_variable_name(constchar *name) { bool saw_sep = false; bool name_start = true;
for (constchar *p = name; *p; p++) { if (*p == GUC_QUALIFIER_SEPARATOR) { if (name_start) returnfalse; /* empty name component */ saw_sep = true; name_start = true; } elseif (strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz", *p) != NULL || IS_HIGHBIT_SET(*p)) { /* okay as first or non-first character */ name_start = false; } elseif (!name_start && strchr("0123456789_$", *p) != NULL) /* okay as non-first character */ ; else returnfalse; } if (name_start) returnfalse; /* empty name component */ /* OK if we found at least one separator */ return saw_sep; }