*** a/src/backend/utils/adt/timestamp.c
--- b/src/backend/utils/adt/timestamp.c
***************
*** 2923,2934 **** timestamp_pl_interval(PG_FUNCTION_ARGS)
  		result = timestamp;
  	else
  	{
  		if (span->month != 0)
  		{
- 			struct pg_tm tt,
- 					   *tm = &tt;
- 			fsec_t		fsec;
- 
  			if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
  				ereport(ERROR,
  						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
--- 2923,2934 ----
  		result = timestamp;
  	else
  	{
+ 		struct pg_tm tt,
+ 				   *tm = &tt;
+ 		fsec_t		fsec;
+ 
  		if (span->month != 0)
  		{
  			if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
  				ereport(ERROR,
  						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
***************
*** 2958,2966 **** timestamp_pl_interval(PG_FUNCTION_ARGS)
  
  		if (span->day != 0)
  		{
- 			struct pg_tm tt,
- 					   *tm = &tt;
- 			fsec_t		fsec;
  			int			julian;
  
  			if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
--- 2958,2963 ----
***************
*** 2978,2984 **** timestamp_pl_interval(PG_FUNCTION_ARGS)
  						 errmsg("timestamp out of range")));
  		}
  
! 		timestamp += span->time;
  		result = timestamp;
  	}
  
--- 2975,2997 ----
  						 errmsg("timestamp out of range")));
  		}
  
! 		if (span->time != 0)
! 		{
! 			/* add time directly to timestamp */
! 			timestamp += span->time;
! 
! 			/* convert back and forth only for consistent error checking */
! 			if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
! 				ereport(ERROR,
! 						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
! 						 errmsg("timestamp out of range")));
! 
! 			if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0)
! 				ereport(ERROR,
! 						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
! 						 errmsg("timestamp out of range")));
! 		}
! 
  		result = timestamp;
  	}
  
***************
*** 3023,3034 **** timestamptz_pl_interval(PG_FUNCTION_ARGS)
  		result = timestamp;
  	else
  	{
  		if (span->month != 0)
  		{
- 			struct pg_tm tt,
- 					   *tm = &tt;
- 			fsec_t		fsec;
- 
  			if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
  				ereport(ERROR,
  						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
--- 3036,3047 ----
  		result = timestamp;
  	else
  	{
+ 		struct pg_tm tt,
+ 				   *tm = &tt;
+ 		fsec_t		fsec;
+ 
  		if (span->month != 0)
  		{
  			if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
  				ereport(ERROR,
  						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
***************
*** 3060,3068 **** timestamptz_pl_interval(PG_FUNCTION_ARGS)
  
  		if (span->day != 0)
  		{
- 			struct pg_tm tt,
- 					   *tm = &tt;
- 			fsec_t		fsec;
  			int			julian;
  
  			if (timestamp2tm(timestamp, &tz, tm, &fsec, NULL, NULL) != 0)
--- 3073,3078 ----
***************
*** 3082,3088 **** timestamptz_pl_interval(PG_FUNCTION_ARGS)
  						 errmsg("timestamp out of range")));
  		}
  
! 		timestamp += span->time;
  		result = timestamp;
  	}
  
--- 3092,3114 ----
  						 errmsg("timestamp out of range")));
  		}
  
! 		if (span->time != 0)
! 		{
! 			/* add time directly to timestamp */
! 			timestamp += span->time;
! 
! 			/* convert back and forth only for consistent error checking */
! 			if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL, NULL) != 0)
! 				ereport(ERROR,
! 						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
! 						 errmsg("timestamp out of range")));
! 
! 			if (tm2timestamp(tm, fsec, NULL, &timestamp) != 0)
! 				ereport(ERROR,
! 						(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
! 						 errmsg("timestamp out of range")));
! 		}
! 
  		result = timestamp;
  	}
  
