diff --git a/doc/src/sgml/ref/create_user_mapping.sgml b/doc/src/sgml/ref/create_user_mapping.sgml
index 3094442..c960628 100644
--- a/doc/src/sgml/ref/create_user_mapping.sgml
+++ b/doc/src/sgml/ref/create_user_mapping.sgml
@@ -34,7 +34,7 @@ CREATE USER MAPPING FOR { user_name
CREATE USER MAPPING defines a mapping of a user
to a foreign server. A user mapping typically encapsulates
connection information that a foreign-data wrapper uses together
- with the information encapsulated be a foreign server to access an
+ with the information encapsulated by a foreign server to access an
external data resource.
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);
}
+