diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index 78bac40..0441aaf 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -1304,7 +1304,6 @@ generate_series_step_int4(PG_FUNCTION_ARGS)
 {
 	FuncCallContext *funcctx;
 	generate_series_fctx *fctx;
-	int32		result;
 	MemoryContext oldcontext;
 
 	/* stuff done only on the first call of the function */
@@ -1343,27 +1342,32 @@ generate_series_step_int4(PG_FUNCTION_ARGS)
 
 		funcctx->user_fctx = fctx;
 		MemoryContextSwitchTo(oldcontext);
+
+		/* send off first value in series */
+		SRF_RETURN_NEXT(funcctx, Int32GetDatum(start));
 	}
 
 	/* stuff done on every call of the function */
 	funcctx = SRF_PERCALL_SETUP();
 
 	/*
-	 * get the saved state and use current as the result for this iteration
+	 * get the saved state
 	 */
 	fctx = funcctx->user_fctx;
-	result = fctx->current;
 
-	if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
-		(fctx->step < 0 && fctx->current >= fctx->finish))
+	if ((fctx->step > 0 && fctx->current < fctx->finish &&
+			fctx->current + fctx->step > fctx->current) ||
+		(fctx->step < 0 && fctx->current > fctx->finish &&
+			fctx->current + fctx->step < fctx->current))
 	{
 		/* increment current in preparation for next iteration */
 		fctx->current += fctx->step;
 
-		/* do when there is more left to send */
-		SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
+		/* send off current value in series */
+		SRF_RETURN_NEXT(funcctx, Int32GetDatum(fctx->current));
 	}
 	else
 		/* do when there is no more left */
 		SRF_RETURN_DONE(funcctx);
 }
+
