Commits

Andrew Dunstan committed c981732

improve hstore_to_json numeric field detection

  • Participants
  • Parent commits 5ba8901
  • Branches jsonng

Comments (0)

Files changed (1)

contrib/hstore/hstore_io.c

 			resetStringInfo(src);
 			appendBinaryStringInfo(src, HS_VAL(entries, base, i), HS_VALLEN(entries, i));
 			/* 
-			 * don't treat something with a leading zero as numeric - 
+			 * don't treat something with a leading zero followed by another digit as numeric - 
 			 * could be a zip code or similar 
 			 */
-			if (src->len > 0 && src->data[0] != '0' &&
+			if (src->len > 0 && (src->data[0] != '0' || !isdigit(src->data[1])) &&
 				strspn(src->data,"+-0123456789Ee.") == src->len)
 			{
 				/* might be a number. See if we can input it as a numeric value*/
 				char * endptr;
-				(void) strtol(src->data,&endptr,10);
+				long longres = strtol(src->data,&endptr,10);
 				if (*endptr == '\0')
 				{
 					/* strol man page says this means the whole string is valid */
 				else
 				{
 					/* not an int - try a double */
-					(void) strtod(src->data,&endptr);
+					double doubleres = strtod(src->data,&endptr);
 					if (*endptr == '\0')
 						is_number = true;
+					else if (false)
+					{
+						/* shut the compiler up about unused variables */
+						longres = (long) doubleres;
+						longres = longres / 2;
+					}
 				}
 			}
 			if (is_number)
 			   *ptr;
 	char	   *base = STRPTR(in);
 	HEntry	   *entries = ARRPTR(in);
-	bool        is_number;
 	StringInfo  src, dst;
 
 	if (count == 0)