mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Allow "SET list_guc TO NULL" to specify setting the GUC to empty.
We have never had a SET syntax that allows setting a GUC_LIST_INPUT parameter to be an empty list. A locution such as SET search_path = ''; doesn't mean that; it means setting the GUC to contain a single item that is an empty string. (For search_path the net effect is much the same, because search_path ignores invalid schema names and '' must be invalid.) This is confusing, not least because configuration-file entries and the set_config() function can easily produce empty-list values. We considered making the empty-string syntax do this, but that would foreclose ever allowing empty-string items to be valid in list GUCs. While there isn't any obvious use-case for that today, it feels like the kind of restriction that might hurt someday. Instead, let's accept the forbidden-up-to-now value NULL and treat that as meaning an empty list. (An objection to this could be "what if we someday want to allow NULL as a GUC value?". That seems unlikely though, and even if we did allow it for scalar GUCs, we could continue to treat it as meaning an empty list for list GUCs.) Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Andrei Klychkov <andrew.a.klychkov@gmail.com> Reviewed-by: Jim Jones <jim.jones@uni-muenster.de> Discussion: https://postgr.es/m/CA+mfrmwsBmYsJayWjc8bJmicxc3phZcHHY=yW5aYe=P-1d_4bg@mail.gmail.com
This commit is contained in:
@@ -1716,6 +1716,26 @@ generic_set:
|
||||
n->location = @3;
|
||||
$$ = n;
|
||||
}
|
||||
| var_name TO NULL_P
|
||||
{
|
||||
VariableSetStmt *n = makeNode(VariableSetStmt);
|
||||
|
||||
n->kind = VAR_SET_VALUE;
|
||||
n->name = $1;
|
||||
n->args = list_make1(makeNullAConst(@3));
|
||||
n->location = @3;
|
||||
$$ = n;
|
||||
}
|
||||
| var_name '=' NULL_P
|
||||
{
|
||||
VariableSetStmt *n = makeNode(VariableSetStmt);
|
||||
|
||||
n->kind = VAR_SET_VALUE;
|
||||
n->name = $1;
|
||||
n->args = list_make1(makeNullAConst(@3));
|
||||
n->location = @3;
|
||||
$$ = n;
|
||||
}
|
||||
| var_name TO DEFAULT
|
||||
{
|
||||
VariableSetStmt *n = makeNode(VariableSetStmt);
|
||||
|
||||
@@ -3087,7 +3087,8 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
|
||||
* string literals. (The elements may be double-quoted as-is,
|
||||
* but we can't just feed them to the SQL parser; it would do
|
||||
* the wrong thing with elements that are zero-length or
|
||||
* longer than NAMEDATALEN.)
|
||||
* longer than NAMEDATALEN.) Also, we need a special case for
|
||||
* empty lists.
|
||||
*
|
||||
* Variables that are not so marked should just be emitted as
|
||||
* simple string literals. If the variable is not known to
|
||||
@@ -3105,6 +3106,9 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
|
||||
/* this shouldn't fail really */
|
||||
elog(ERROR, "invalid list syntax in proconfig item");
|
||||
}
|
||||
/* Special case: represent an empty list as NULL */
|
||||
if (namelist == NIL)
|
||||
appendStringInfoString(&buf, "NULL");
|
||||
foreach(lc, namelist)
|
||||
{
|
||||
char *curname = (char *) lfirst(lc);
|
||||
|
||||
@@ -2753,7 +2753,7 @@ SplitIdentifierString(char *rawstring, char separator,
|
||||
nextp++; /* skip leading whitespace */
|
||||
|
||||
if (*nextp == '\0')
|
||||
return true; /* allow empty string */
|
||||
return true; /* empty string represents empty list */
|
||||
|
||||
/* At the top of the loop, we are at start of a new identifier. */
|
||||
do
|
||||
@@ -2880,7 +2880,7 @@ SplitDirectoriesString(char *rawstring, char separator,
|
||||
nextp++; /* skip leading whitespace */
|
||||
|
||||
if (*nextp == '\0')
|
||||
return true; /* allow empty string */
|
||||
return true; /* empty string represents empty list */
|
||||
|
||||
/* At the top of the loop, we are at start of a new directory. */
|
||||
do
|
||||
@@ -3001,7 +3001,7 @@ SplitGUCList(char *rawstring, char separator,
|
||||
nextp++; /* skip leading whitespace */
|
||||
|
||||
if (*nextp == '\0')
|
||||
return true; /* allow empty string */
|
||||
return true; /* empty string represents empty list */
|
||||
|
||||
/* At the top of the loop, we are at start of a new identifier. */
|
||||
do
|
||||
|
||||
@@ -210,12 +210,29 @@ flatten_set_variable_args(const char *name, List *args)
|
||||
else
|
||||
flags = 0;
|
||||
|
||||
/* Complain if list input and non-list variable */
|
||||
if ((flags & GUC_LIST_INPUT) == 0 &&
|
||||
list_length(args) != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("SET %s takes only one argument", name)));
|
||||
/*
|
||||
* Handle special cases for list input.
|
||||
*/
|
||||
if (flags & GUC_LIST_INPUT)
|
||||
{
|
||||
/* NULL represents an empty list. */
|
||||
if (list_length(args) == 1)
|
||||
{
|
||||
Node *arg = (Node *) linitial(args);
|
||||
|
||||
if (IsA(arg, A_Const) &&
|
||||
((A_Const *) arg)->isnull)
|
||||
return pstrdup("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Complain if list input and non-list variable. */
|
||||
if (list_length(args) != 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("SET %s takes only one argument", name)));
|
||||
}
|
||||
|
||||
initStringInfo(&buf);
|
||||
|
||||
@@ -246,6 +263,12 @@ flatten_set_variable_args(const char *name, List *args)
|
||||
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
|
||||
con = (A_Const *) arg;
|
||||
|
||||
/* Complain if NULL is used with a non-list variable. */
|
||||
if (con->isnull)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("NULL is an invalid value for %s", name)));
|
||||
|
||||
switch (nodeTag(&con->val))
|
||||
{
|
||||
case T_Integer:
|
||||
@@ -269,6 +292,9 @@ flatten_set_variable_args(const char *name, List *args)
|
||||
Datum interval;
|
||||
char *intervalout;
|
||||
|
||||
/* gram.y ensures this is only reachable for TIME ZONE */
|
||||
Assert(!(flags & GUC_LIST_QUOTE));
|
||||
|
||||
typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
|
||||
Assert(typoid == INTERVALOID);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user