Index: src/backend/utils/adt/formatting.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v
retrieving revision 1.122
diff -c -c -r1.122 formatting.c
*** src/backend/utils/adt/formatting.c	9 Feb 2007 04:17:58 -0000	1.122
--- src/backend/utils/adt/formatting.c	9 Feb 2007 04:19:18 -0000
***************
*** 3835,3848 ****
  			Np->L_positive_sign = "+";
  
  		/*
- 		 * Number thousands separator
- 		 */
- 		if (lconv->thousands_sep && *lconv->thousands_sep)
- 			Np->L_thousands_sep = lconv->thousands_sep;
- 		else
- 			Np->L_thousands_sep = ",";
- 
- 		/*
  		 * Number decimal point
  		 */
  		if (lconv->decimal_point && *lconv->decimal_point)
--- 3835,3840 ----
***************
*** 3850,3855 ****
--- 3842,3867 ----
  		else
  			Np->decimal = ".";
  
+ 		/* If they didn't ask for locale-specific decimal */
+ 		if (!IS_LDECIMAL(Np->Num))
+ 			Np->decimal = ".";
+ 
+ 		/*
+ 		 * Number thousands separator
+ 		 */
+ 		if (lconv->thousands_sep && *lconv->thousands_sep)
+ 			Np->L_thousands_sep = lconv->thousands_sep;
+ 		/*
+ 		 *	Some locales (e.g. broken glibc pt_BR), have a comma for
+ 		 *	decimal, but "" for thousands_sep, so we certainly
+ 		 *	don't want to make the thousands_sep comma too, so
+ 		 *	we just leave it blank.
+ 		 */
+ 		else if (*Np->decimal != ',')
+ 			Np->L_thousands_sep = ",";
+ 		else
+ 			Np->L_thousands_sep = "";
+ 		
  		/*
  		 * Currency symbol
  		 */
***************
*** 3857,3865 ****
  			Np->L_currency_symbol = lconv->currency_symbol;
  		else
  			Np->L_currency_symbol = " ";
- 
- 		if (!IS_LDECIMAL(Np->Num))
- 			Np->decimal = ".";
  	}
  	else
  	{
--- 3869,3874 ----
