@ -12,6 +12,7 @@
# include "libpq/pqformat.h"
# include "libpq/pqformat.h"
# include "utils/builtins.h"
# include "utils/builtins.h"
# include "utils/json.h"
# include "utils/json.h"
# include "utils/jsonapi.h"
# include "utils/jsonb.h"
# include "utils/jsonb.h"
# include "utils/lsyscache.h"
# include "utils/lsyscache.h"
# include "utils/memutils.h"
# include "utils/memutils.h"
@ -1240,7 +1241,6 @@ hstore_to_json_loose(PG_FUNCTION_ARGS)
int count = HS_COUNT ( in ) ;
int count = HS_COUNT ( in ) ;
char * base = STRPTR ( in ) ;
char * base = STRPTR ( in ) ;
HEntry * entries = ARRPTR ( in ) ;
HEntry * entries = ARRPTR ( in ) ;
bool is_number ;
StringInfoData tmp ,
StringInfoData tmp ,
dst ;
dst ;
@ -1267,48 +1267,9 @@ hstore_to_json_loose(PG_FUNCTION_ARGS)
appendStringInfoString ( & dst , " false " ) ;
appendStringInfoString ( & dst , " false " ) ;
else
else
{
{
is_number = false ;
resetStringInfo ( & tmp ) ;
resetStringInfo ( & tmp ) ;
appendBinaryStringInfo ( & tmp , HS_VAL ( entries , base , i ) , HS_VALLEN ( entries , i ) ) ;
appendBinaryStringInfo ( & tmp , HS_VAL ( entries , base , i ) , HS_VALLEN ( entries , i ) ) ;
if ( IsValidJsonNumber ( tmp . data , tmp . len ) )
/*
* don ' t treat something with a leading zero followed by another
* digit as numeric - could be a zip code or similar
*/
if ( tmp . len > 0 & &
! ( tmp . data [ 0 ] = = ' 0 ' & &
isdigit ( ( unsigned char ) tmp . data [ 1 ] ) ) & &
strspn ( tmp . data , " +-0123456789Ee. " ) = = tmp . len )
{
/*
* might be a number . See if we can input it as a numeric
* value . Ignore any actual parsed value .
*/
char * endptr = " junk " ;
long lval ;
lval = strtol ( tmp . data , & endptr , 10 ) ;
( void ) lval ;
if ( * endptr = = ' \0 ' )
{
/*
* strol man page says this means the whole string is
* valid
*/
is_number = true ;
}
else
{
/* not an int - try a double */
double dval ;
dval = strtod ( tmp . data , & endptr ) ;
( void ) dval ;
if ( * endptr = = ' \0 ' )
is_number = true ;
}
}
if ( is_number )
appendBinaryStringInfo ( & dst , tmp . data , tmp . len ) ;
appendBinaryStringInfo ( & dst , tmp . data , tmp . len ) ;
else
else
escape_json ( & dst , tmp . data ) ;
escape_json ( & dst , tmp . data ) ;