* Evaluate the limit/offset expressions --- done at startup or rescan. * * This is also a handy place to reset the current-position state info. */
| 375 | * This is also a handy place to reset the current-position state info. |
| 376 | */ |
| 377 | static void |
| 378 | recompute_limits(LimitState *node) |
| 379 | { |
| 380 | ExprContext *econtext = node->ps.ps_ExprContext; |
| 381 | Datum val; |
| 382 | bool isNull; |
| 383 | |
| 384 | if (node->limitOffset) |
| 385 | { |
| 386 | val = ExecEvalExprSwitchContext(node->limitOffset, |
| 387 | econtext, |
| 388 | &isNull); |
| 389 | /* Interpret NULL offset as no offset */ |
| 390 | if (isNull) |
| 391 | node->offset = 0; |
| 392 | else |
| 393 | { |
| 394 | node->offset = DatumGetInt64(val); |
| 395 | if (node->offset < 0) |
| 396 | ereport(ERROR, |
| 397 | (errcode(ERRCODE_INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE), |
| 398 | errmsg("OFFSET must not be negative"))); |
| 399 | } |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | /* No OFFSET supplied */ |
| 404 | node->offset = 0; |
| 405 | } |
| 406 | |
| 407 | if (node->limitCount) |
| 408 | { |
| 409 | val = ExecEvalExprSwitchContext(node->limitCount, |
| 410 | econtext, |
| 411 | &isNull); |
| 412 | /* Interpret NULL count as no count (LIMIT ALL) */ |
| 413 | if (isNull) |
| 414 | { |
| 415 | node->count = 0; |
| 416 | node->noCount = true; |
| 417 | } |
| 418 | else |
| 419 | { |
| 420 | node->count = DatumGetInt64(val); |
| 421 | if (node->count < 0) |
| 422 | ereport(ERROR, |
| 423 | (errcode(ERRCODE_INVALID_ROW_COUNT_IN_LIMIT_CLAUSE), |
| 424 | errmsg("LIMIT must not be negative"))); |
| 425 | node->noCount = false; |
| 426 | } |
| 427 | } |
| 428 | else |
| 429 | { |
| 430 | /* No COUNT supplied */ |
| 431 | node->count = 0; |
| 432 | node->noCount = true; |
| 433 | } |
| 434 |
no test coverage detected