@ -32,9 +32,6 @@
# include "utils/typcache.h"
# include "utils/typcache.h"
# include "utils/syscache.h"
# include "utils/syscache.h"
/* String to output for infinite dates and timestamps */
# define DT_INFINITY "\"infinity\""
/*
/*
* The context of the parser is maintained by the recursive descent
* The context of the parser is maintained by the recursive descent
* mechanism , but is passed explicitly to the error reporting routine
* mechanism , but is passed explicitly to the error reporting routine
@ -365,8 +362,8 @@ json_count_array_elements(JsonLexContext *lex)
/*
/*
* It ' s safe to do this with a shallow copy because the lexical routines
* It ' s safe to do this with a shallow copy because the lexical routines
* don ' t scribble on the input . They do scribble on the other pointers etc ,
* don ' t scribble on the input . They do scribble on the other pointers
* so doing this with a copy makes that safe .
* etc , so doing this with a copy makes that safe .
*/
*/
memcpy ( & copylex , lex , sizeof ( JsonLexContext ) ) ;
memcpy ( & copylex , lex , sizeof ( JsonLexContext ) ) ;
copylex . strval = NULL ; /* not interested in values here */
copylex . strval = NULL ; /* not interested in values here */
@ -1492,19 +1489,16 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
char buf [ MAXDATELEN + 1 ] ;
char buf [ MAXDATELEN + 1 ] ;
date = DatumGetDateADT ( val ) ;
date = DatumGetDateADT ( val ) ;
/* Same as date_out(), but forcing DateStyle */
if ( DATE_NOT_FINITE ( date ) )
if ( DATE_NOT_FINITE ( date ) )
{
EncodeSpecialDate ( date , buf ) ;
/* we have to format infinity ourselves */
appendStringInfoString ( result , DT_INFINITY ) ;
}
else
else
{
{
j2date ( date + POSTGRES_EPOCH_JDATE ,
j2date ( date + POSTGRES_EPOCH_JDATE ,
& ( tm . tm_year ) , & ( tm . tm_mon ) , & ( tm . tm_mday ) ) ;
& ( tm . tm_year ) , & ( tm . tm_mon ) , & ( tm . tm_mday ) ) ;
EncodeDateOnly ( & tm , USE_XSD_DATES , buf ) ;
EncodeDateOnly ( & tm , USE_XSD_DATES , buf ) ;
appendStringInfo ( result , " \" %s \" " , buf ) ;
}
}
appendStringInfo ( result , " \" %s \" " , buf ) ;
}
}
break ;
break ;
case JSONTYPE_TIMESTAMP :
case JSONTYPE_TIMESTAMP :
@ -1515,21 +1509,16 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
char buf [ MAXDATELEN + 1 ] ;
char buf [ MAXDATELEN + 1 ] ;
timestamp = DatumGetTimestamp ( val ) ;
timestamp = DatumGetTimestamp ( val ) ;
/* Same as timestamp_out(), but forcing DateStyle */
if ( TIMESTAMP_NOT_FINITE ( timestamp ) )
if ( TIMESTAMP_NOT_FINITE ( timestamp ) )
{
EncodeSpecialTimestamp ( timestamp , buf ) ;
/* we have to format infinity ourselves */
appendStringInfoString ( result , DT_INFINITY ) ;
}
else if ( timestamp2tm ( timestamp , NULL , & tm , & fsec , NULL , NULL ) = = 0 )
else if ( timestamp2tm ( timestamp , NULL , & tm , & fsec , NULL , NULL ) = = 0 )
{
EncodeDateTime ( & tm , fsec , false , 0 , NULL , USE_XSD_DATES , buf ) ;
EncodeDateTime ( & tm , fsec , false , 0 , NULL , USE_XSD_DATES , buf ) ;
appendStringInfo ( result , " \" %s \" " , buf ) ;
}
else
else
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ) ,
( errcode ( ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ) ,
errmsg ( " timestamp out of range " ) ) ) ;
errmsg ( " timestamp out of range " ) ) ) ;
appendStringInfo ( result , " \" %s \" " , buf ) ;
}
}
break ;
break ;
case JSONTYPE_TIMESTAMPTZ :
case JSONTYPE_TIMESTAMPTZ :
@ -1541,22 +1530,17 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
const char * tzn = NULL ;
const char * tzn = NULL ;
char buf [ MAXDATELEN + 1 ] ;
char buf [ MAXDATELEN + 1 ] ;
timestamp = DatumGetTimestamp ( val ) ;
timestamp = DatumGetTimestampTz ( val ) ;
/* Same as timestamptz_out(), but forcing DateStyle */
if ( TIMESTAMP_NOT_FINITE ( timestamp ) )
if ( TIMESTAMP_NOT_FINITE ( timestamp ) )
{
EncodeSpecialTimestamp ( timestamp , buf ) ;
/* we have to format infinity ourselves */
appendStringInfoString ( result , DT_INFINITY ) ;
}
else if ( timestamp2tm ( timestamp , & tz , & tm , & fsec , & tzn , NULL ) = = 0 )
else if ( timestamp2tm ( timestamp , & tz , & tm , & fsec , & tzn , NULL ) = = 0 )
{
EncodeDateTime ( & tm , fsec , true , tz , tzn , USE_XSD_DATES , buf ) ;
EncodeDateTime ( & tm , fsec , true , tz , tzn , USE_XSD_DATES , buf ) ;
appendStringInfo ( result , " \" %s \" " , buf ) ;
}
else
else
ereport ( ERROR ,
ereport ( ERROR ,
( errcode ( ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ) ,
( errcode ( ERRCODE_DATETIME_VALUE_OUT_OF_RANGE ) ,
errmsg ( " timestamp out of range " ) ) ) ;
errmsg ( " timestamp out of range " ) ) ) ;
appendStringInfo ( result , " \" %s \" " , buf ) ;
}
}
break ;
break ;
case JSONTYPE_JSON :
case JSONTYPE_JSON :
@ -1905,7 +1889,7 @@ json_agg_transfn(PG_FUNCTION_ARGS)
MemoryContextSwitchTo ( oldcontext ) ;
MemoryContextSwitchTo ( oldcontext ) ;
appendStringInfoChar ( state - > str , ' [ ' ) ;
appendStringInfoChar ( state - > str , ' [ ' ) ;
json_categorize_type ( arg_type , & state - > val_category ,
json_categorize_type ( arg_type , & state - > val_category ,
& state - > val_output_func ) ;
& state - > val_output_func ) ;
}
}
else
else
@ -2007,7 +1991,7 @@ json_object_agg_transfn(PG_FUNCTION_ARGS)
( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) ,
( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) ,
errmsg ( " could not determine data type for argument 1 " ) ) ) ;
errmsg ( " could not determine data type for argument 1 " ) ) ) ;
json_categorize_type ( arg_type , & state - > key_category ,
json_categorize_type ( arg_type , & state - > key_category ,
& state - > key_output_func ) ;
& state - > key_output_func ) ;
arg_type = get_fn_expr_argtype ( fcinfo - > flinfo , 2 ) ;
arg_type = get_fn_expr_argtype ( fcinfo - > flinfo , 2 ) ;
@ -2017,7 +2001,7 @@ json_object_agg_transfn(PG_FUNCTION_ARGS)
( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) ,
( errcode ( ERRCODE_INVALID_PARAMETER_VALUE ) ,
errmsg ( " could not determine data type for argument 2 " ) ) ) ;
errmsg ( " could not determine data type for argument 2 " ) ) ) ;
json_categorize_type ( arg_type , & state - > val_category ,
json_categorize_type ( arg_type , & state - > val_category ,
& state - > val_output_func ) ;
& state - > val_output_func ) ;
appendStringInfoString ( state - > str , " { " ) ;
appendStringInfoString ( state - > str , " { " ) ;