mirror of
https://github.com/postgres/postgres.git
synced 2025-05-05 09:19:17 +03:00
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.
This commit is contained in:
parent
dca4d77798
commit
7f676624f6
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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.27.2.1 2006/12/03 21:40:13 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -225,20 +225,24 @@ static void
|
|||||||
recompute_limits(LimitState *node)
|
recompute_limits(LimitState *node)
|
||||||
{
|
{
|
||||||
ExprContext *econtext = node->ps.ps_ExprContext;
|
ExprContext *econtext = node->ps.ps_ExprContext;
|
||||||
|
Datum val;
|
||||||
bool isNull;
|
bool isNull;
|
||||||
|
|
||||||
if (node->limitOffset)
|
if (node->limitOffset)
|
||||||
{
|
{
|
||||||
node->offset =
|
val = ExecEvalExprSwitchContext(node->limitOffset,
|
||||||
DatumGetInt64(ExecEvalExprSwitchContext(node->limitOffset,
|
econtext,
|
||||||
econtext,
|
&isNull,
|
||||||
&isNull,
|
NULL);
|
||||||
NULL));
|
|
||||||
/* Interpret NULL offset as no offset */
|
/* Interpret NULL offset as no offset */
|
||||||
if (isNull)
|
if (isNull)
|
||||||
node->offset = 0;
|
node->offset = 0;
|
||||||
else if (node->offset < 0)
|
else
|
||||||
node->offset = 0;
|
{
|
||||||
|
node->offset = DatumGetInt64(val);
|
||||||
|
if (node->offset < 0)
|
||||||
|
node->offset = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -248,17 +252,23 @@ recompute_limits(LimitState *node)
|
|||||||
|
|
||||||
if (node->limitCount)
|
if (node->limitCount)
|
||||||
{
|
{
|
||||||
node->noCount = false;
|
val = ExecEvalExprSwitchContext(node->limitCount,
|
||||||
node->count =
|
econtext,
|
||||||
DatumGetInt64(ExecEvalExprSwitchContext(node->limitCount,
|
&isNull,
|
||||||
econtext,
|
NULL);
|
||||||
&isNull,
|
|
||||||
NULL));
|
|
||||||
/* Interpret NULL count as no count (LIMIT ALL) */
|
/* Interpret NULL count as no count (LIMIT ALL) */
|
||||||
if (isNull)
|
if (isNull)
|
||||||
node->noCount = true;
|
{
|
||||||
else if (node->count < 0)
|
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user