Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfce56e

Browse files
committed
Throw an error for negative LIMIT or OFFSET values, instead of silently
treating them as zero. Simon Riggs
1 parent 2abf130 commit bfce56e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/backend/executor/nodeLimit.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.33 2008/01/01 19:45:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.34 2008/03/10 03:37:59 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -246,7 +246,9 @@ recompute_limits(LimitState *node)
246246
{
247247
node->offset = DatumGetInt64(val);
248248
if (node->offset < 0)
249-
node->offset = 0;
249+
ereport(ERROR,
250+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
251+
errmsg("OFFSET must not be negative")));
250252
}
251253
}
252254
else
@@ -271,7 +273,9 @@ recompute_limits(LimitState *node)
271273
{
272274
node->count = DatumGetInt64(val);
273275
if (node->count < 0)
274-
node->count = 0;
276+
ereport(ERROR,
277+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
278+
errmsg("LIMIT must not be negative")));
275279
node->noCount = false;
276280
}
277281
}

0 commit comments

Comments
 (0)