src/backend/utils/misc/guc.c
char *
flatten_set_variable_args(const char *name, List *args)
{
	struct config_generic *record;
	int			flags;
	StringInfoData buf;
	ListCell   *l;

	/*
	 * Fast path if just DEFAULT.  We do not check the variable name in this
	 * case --- necessary for RESET ALL to work correctly.
	 */
	if (args == NIL)
		return NULL;

	/* Else get flags for the variable */
	record = find_option(name, ERROR);
	if (record == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_UNDEFINED_OBJECT),
			   errmsg("unrecognized configuration parameter \"%s\"", name)));

	flags = record->flags;

	/* 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)));

	initStringInfo(&buf);

	foreach(l, args)
	{
		A_Const    *arg = (A_Const *) lfirst(l);
		char	   *val;

		if (l != list_head(args))
			appendStringInfo(&buf, ", ");

		if (!IsA(arg, A_Const))
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));

		switch (nodeTag(&arg->val))
		{
			case T_Integer:
				appendStringInfo(&buf, "%ld", intVal(&arg->val));
				break;
			case T_Float:
				/* represented as a string, so just copy it */
				appendStringInfoString(&buf, strVal(&arg->val));
				break;
			case T_String:
				val = strVal(&arg->val);
				if (arg->typname != NULL)
				{
					/*
					 * Must be a ConstInterval argument for TIME ZONE. Coerce
					 * to interval and back to normalize the value and account
					 * for any typmod.
					 */
					Datum		interval;
					char	   *intervalout;

					interval =
						DirectFunctionCall3(interval_in,
											CStringGetDatum(val),
											ObjectIdGetDatum(InvalidOid),
									   Int32GetDatum(arg->typname->typmod));

					intervalout =
						DatumGetCString(DirectFunctionCall1(interval_out,
															interval));
					appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
				}
				else
				{
					/*
					 * Plain string literal or identifier.	For quote mode,
					 * quote it if it's not a vanilla identifier.
					 */
					if (flags & GUC_LIST_QUOTE)
						appendStringInfoString(&buf, quote_identifier(val));
					else
						appendStringInfoString(&buf, val);
				}
				break;
			default:
				elog(ERROR, "unrecognized node type: %d",
					 (int) nodeTag(&arg->val));
				break;
		}
	}

	return buf.data;
}
/*
 * flatten_set_variable_args
 *		Given a parsenode List as emitted by the grammar for SET,
 *		convert to the flat string representation used by GUC.
 *
 * We need to be told the name of the variable the args are for, because
 * the flattening rules vary (ugh).
 *
 * The result is NULL if input is NIL (ie, SET ... TO DEFAULT), otherwise
 * a palloc'd string.
 */
flatten_set_variable_args
Given a parsenode List as emitted by the grammar for SET,
convert to the flat string representation used by GUC.

We need to be told the name of the variable the args are for, because
the flattening rules vary (ugh).

The result is NULL if input is NIL , otherwise
a palloc'd string.
flatten_set_variable_args Given a parsenode List as emitted by the grammar for SET convert to the flat string representation used by GUC . We need to be told the name of the variable the args are for because the flattening rules vary ( ugh ) . The result is NULL if input is NIL otherwise a palloc ' d string .
char *
flatten_set_variable_args(const char *name, List *args)
{
	struct config_generic *record;
	int			flags;
	StringInfoData buf;
	ListCell   *l;
	if (args == NIL)
		return NULL;
	record = find_option(name, ERROR);
	if (record == NULL)
		ereport(ERROR,
				(errcode(ERRCODE_UNDEFINED_OBJECT),
			   errmsg("unrecognized configuration parameter \"%s\"", name)));
	flags = record->flags;
	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)));
	initStringInfo(&buf);
	foreach(l, args)
	{
		A_Const    *arg = (A_Const *) lfirst(l);
		char	   *val;
		if (l != list_head(args))
			appendStringInfo(&buf, ", ");
		if (!IsA(arg, A_Const))
			elog(ERROR, "unrecognized node type: %d", (int) nodeTag(arg));
		switch (nodeTag(&arg->val))
		{
			case T_Integer:
				appendStringInfo(&buf, "%ld", intVal(&arg->val));
				break;
			case T_Float:
				appendStringInfoString(&buf, strVal(&arg->val));
				break;
			case T_String:
				val = strVal(&arg->val);
				if (arg->typname != NULL)
				{
					Datum		interval;
					char	   *intervalout;
					interval =
						DirectFunctionCall3(interval_in,
											CStringGetDatum(val),
											ObjectIdGetDatum(InvalidOid),
									   Int32GetDatum(arg->typname->typmod));
					intervalout =
						DatumGetCString(DirectFunctionCall1(interval_out,
															interval));
					appendStringInfo(&buf, "INTERVAL '%s'", intervalout);
				}
				else
				{
					if (flags & GUC_LIST_QUOTE)
						appendStringInfoString(&buf, quote_identifier(val));
					else
						appendStringInfoString(&buf, val);
				}
				break;
			default:
				elog(ERROR, "unrecognized node type: %d",
					 (int) nodeTag(&arg->val));
				break;
		}
	}
	return buf.data;
}
char * flatten_set_variable_args ( const char * name , List * args ) { struct config_generic * record ; int flags ; StringInfoData buf ; ListCell * l ; if ( args == NIL ) return NULL ; record = find_option ( name , ERROR ) ; if ( record == NULL ) ereport ( ERROR , ( errcode ( ERRCODE_UNDEFINED_OBJECT ) , errmsg ( " \" \" " , name ) ) ) ; flags = record -> flags ; if ( ( flags & GUC_LIST_INPUT ) == 0 && list_length ( args ) != 1 ) ereport ( ERROR , ( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) , errmsg ( " " , name ) ) ) ; initStringInfo ( & buf ) ; foreach ( l , args ) { A_Const * arg = ( A_Const * ) lfirst ( l ) ; char * val ; if ( l != list_head ( args ) ) appendStringInfo ( & buf , " " ) ; if ( ! IsA ( arg , A_Const ) ) elog ( ERROR , " " , ( int ) nodeTag ( arg ) ) ; switch ( nodeTag ( & arg -> val ) ) { case T_Integer : appendStringInfo ( & buf , " " , intVal ( & arg -> val ) ) ; break ; case T_Float : appendStringInfoString ( & buf , strVal ( & arg -> val ) ) ; break ; case T_String : val = strVal ( & arg -> val ) ; if ( arg -> typname != NULL ) { Datum interval ; char * intervalout ; interval = DirectFunctionCall3 ( interval_in , CStringGetDatum ( val ) , ObjectIdGetDatum ( InvalidOid ) , Int32GetDatum ( arg -> typname -> typmod ) ) ; intervalout = DatumGetCString ( DirectFunctionCall1 ( interval_out , interval ) ) ; appendStringInfo ( & buf , " " , intervalout ) ; } else { if ( flags & GUC_LIST_QUOTE ) appendStringInfoString ( & buf , quote_identifier ( val ) ) ; else appendStringInfoString ( & buf , val ) ; } break ; default : elog ( ERROR , " " , ( int ) nodeTag ( & arg -> val ) ) ; break ; } } return buf . data ; }
flatten_set_variable_args
              Given a parsenode List as emitted by the grammar for SET,
              convert to the flat string representation used by GUC.
flatten_set_variable_args Given a parsenode List as emitted by the grammar for SET convert to the flat string representation used by GUC .
/*
	 * Fast path if just DEFAULT.  We do not check the variable name in this
	 * case --- necessary for RESET ALL to work correctly.
	 */ /* Else get flags for the variable */ /* Complain if list input and non-list variable */ /* represented as a string, so just copy it */ /*
					 * Must be a ConstInterval argument for TIME ZONE. Coerce
					 * to interval and back to normalize the value and account
					 * for any typmod.
					 */ /*
					 * Plain string literal or identifier.	For quote mode,
					 * quote it if it's not a vanilla identifier.
					 */