Skip to content

Commit 3c184d1

Browse files
author
Thomas G. Lockhart
committed
Convert GUC parameters back to strings if input as integers.
Change elog(ERROR) messages to say that a variable takes one parameter, rather than saying that it does not take multiple parameters.
1 parent 58ca6e0 commit 3c184d1

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/backend/commands/variable.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.64 2002/04/22 14:34:27 thomas Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.65 2002/04/22 15:13:53 thomas Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -287,7 +287,8 @@ parse_datestyle(List *args)
287287
Value *s;
288288
Assert(IsA(type->names, List));
289289
s = (Value *) lfirst(type->names);
290-
elog(ERROR, "SET DATESTYLE does not allow input of type %s", s->val.str);
290+
elog(ERROR, "SET DATESTYLE does not allow input of type %s"
291+
"\n\tUse an untyped string instead", s->val.str);
291292
}
292293

293294
value = v->val.str;
@@ -594,7 +595,7 @@ parse_XactIsoLevel(List *args)
594595
Assert(IsA(lfirst(args), A_Const));
595596
/* Should only get one argument from the parser */
596597
if (lnext(args) != NIL)
597-
elog(ERROR, "SET TRANSACTION ISOLATION LEVEL does not allow multiple arguments");
598+
elog(ERROR, "SET TRANSACTION ISOLATION LEVEL takes only one argument");
598599

599600
Assert(((A_Const *) lfirst(args))->val.type = T_String);
600601
value = ((A_Const *) lfirst(args))->val.val.str;
@@ -657,7 +658,7 @@ parse_random_seed(List *args)
657658
Assert(IsA(args, List));
658659
/* Should only get one argument from the parser */
659660
if (lnext(args) != NIL)
660-
elog(ERROR, "SET SEED does not allow multiple arguments");
661+
elog(ERROR, "SET SEED takes only one argument");
661662

662663
p = lfirst(args);
663664
Assert(IsA(p, A_Const));
@@ -720,7 +721,7 @@ parse_client_encoding(List *args)
720721
return reset_client_encoding();
721722

722723
if (lnext(args) != NIL)
723-
elog(ERROR, "SET CLIENT ENCODING does not allow multiple arguments");
724+
elog(ERROR, "SET CLIENT ENCODING takes only one argument");
724725

725726
Assert(IsA(lfirst(args), A_Const));
726727
if (((A_Const *) lfirst(args))->val.type != T_String)
@@ -852,15 +853,23 @@ SetPGVariable(const char *name, List *args)
852853
elog(ERROR, "SET %s takes only one argument", name);
853854

854855
n = (A_Const *) lfirst(args);
855-
/* If this is a T_Integer, then we should convert back to a string
856-
* but for now we just reject the parameter.
857-
*/
858-
if ((n->val.type != T_String)
859-
&& (n->val.type != T_Float))
860-
elog(ERROR, "SET requires a string argument for this parameter"
861-
"\n\tInternal coding error: report to thomas@fourpalms.org");
862-
863-
value = n->val.val.str;
856+
if ((n->val.type == T_String)
857+
|| (n->val.type == T_Float))
858+
{
859+
value = n->val.val.str;
860+
}
861+
else if (n->val.type == T_Integer)
862+
{
863+
/* We should convert back to a string. */
864+
value = DatumGetCString(DirectFunctionCall1(int4out, Int32GetDatum(n->val.val.ival)));
865+
}
866+
else
867+
{
868+
elog(ERROR, "SET %s accepts a string argument for this parameter"
869+
"\n\tInternal coding error: report to thomas@fourpalms.org",
870+
name);
871+
value = NULL;
872+
}
864873
}
865874
else
866875
{

0 commit comments

Comments
 (0)