aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeLimit.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-12-03 21:40:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-12-03 21:40:07 +0000
commit406d028a9bb1a531d8e413918709f8d99f5c7783 (patch)
tree82fe4ff467583c7c22467e8880d670034964e982 /src/backend/executor/nodeLimit.c
parent75330c3205648fc4844cbd658a16a5639f4541ee (diff)
downloadpostgresql-406d028a9bb1a531d8e413918709f8d99f5c7783.tar.gz
postgresql-406d028a9bb1a531d8e413918709f8d99f5c7783.zip
Fix LIMIT/OFFSET for null limit values. This worked before 8.2 but was broken
by the change to make limit values int8 instead of int4. (Specifically, you can do DatumGetInt32 safely on a null value, but not DatumGetInt64.) Per bug #2803 from Greg Johnson.
Diffstat (limited to 'src/backend/executor/nodeLimit.c')
-rw-r--r--src/backend/executor/nodeLimit.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c
index 935b59a7223..8455375c602 100644
--- a/src/backend/executor/nodeLimit.c
+++ b/src/backend/executor/nodeLimit.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.27 2006/07/26 19:31:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.28 2006/12/03 21:40:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -225,20 +225,24 @@ static void
recompute_limits(LimitState *node)
{
ExprContext *econtext = node->ps.ps_ExprContext;
+ Datum val;
bool isNull;
if (node->limitOffset)
{
- node->offset =
- DatumGetInt64(ExecEvalExprSwitchContext(node->limitOffset,
- econtext,
- &isNull,
- NULL));
+ val = ExecEvalExprSwitchContext(node->limitOffset,
+ econtext,
+ &isNull,
+ NULL);
/* Interpret NULL offset as no offset */
if (isNull)
node->offset = 0;
- else if (node->offset < 0)
- node->offset = 0;
+ else
+ {
+ node->offset = DatumGetInt64(val);
+ if (node->offset < 0)
+ node->offset = 0;
+ }
}
else
{
@@ -248,17 +252,23 @@ recompute_limits(LimitState *node)
if (node->limitCount)
{
- node->noCount = false;
- node->count =
- DatumGetInt64(ExecEvalExprSwitchContext(node->limitCount,
- econtext,
- &isNull,
- NULL));
+ val = ExecEvalExprSwitchContext(node->limitCount,
+ econtext,
+ &isNull,
+ NULL);
/* Interpret NULL count as no count (LIMIT ALL) */
if (isNull)
- node->noCount = true;
- else if (node->count < 0)
+ {
node->count = 0;
+ node->noCount = true;
+ }
+ else
+ {
+ node->count = DatumGetInt64(val);
+ if (node->count < 0)
+ node->count = 0;
+ node->noCount = false;
+ }
}
else
{