Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit406d028

Browse files
committed
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, youcan do DatumGetInt32 safely on a null value, but not DatumGetInt64.) Perbug #2803 from Greg Johnson.
1 parent75330c3 commit406d028

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

‎src/backend/executor/nodeLimit.c

Lines changed: 26 additions & 16 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.27 2006/07/26 19:31:50 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeLimit.c,v 1.28 2006/12/03 21:40:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -225,20 +225,24 @@ static void
225225
recompute_limits(LimitState*node)
226226
{
227227
ExprContext*econtext=node->ps.ps_ExprContext;
228+
Datumval;
228229
boolisNull;
229230

230231
if (node->limitOffset)
231232
{
232-
node->offset=
233-
DatumGetInt64(ExecEvalExprSwitchContext(node->limitOffset,
234-
econtext,
235-
&isNull,
236-
NULL));
233+
val=ExecEvalExprSwitchContext(node->limitOffset,
234+
econtext,
235+
&isNull,
236+
NULL);
237237
/* Interpret NULL offset as no offset */
238238
if (isNull)
239239
node->offset=0;
240-
elseif (node->offset<0)
241-
node->offset=0;
240+
else
241+
{
242+
node->offset=DatumGetInt64(val);
243+
if (node->offset<0)
244+
node->offset=0;
245+
}
242246
}
243247
else
244248
{
@@ -248,17 +252,23 @@ recompute_limits(LimitState *node)
248252

249253
if (node->limitCount)
250254
{
251-
node->noCount= false;
252-
node->count=
253-
DatumGetInt64(ExecEvalExprSwitchContext(node->limitCount,
254-
econtext,
255-
&isNull,
256-
NULL));
255+
val=ExecEvalExprSwitchContext(node->limitCount,
256+
econtext,
257+
&isNull,
258+
NULL);
257259
/* Interpret NULL count as no count (LIMIT ALL) */
258260
if (isNull)
259-
node->noCount= true;
260-
elseif (node->count<0)
261+
{
261262
node->count=0;
263+
node->noCount= true;
264+
}
265+
else
266+
{
267+
node->count=DatumGetInt64(val);
268+
if (node->count<0)
269+
node->count=0;
270+
node->noCount= false;
271+
}
262272
}
263273
else
264274
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp