Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions expected/pg_rational_test.out
Original file line number Diff line number Diff line change
Expand Up @@ -688,3 +688,8 @@ select rational_intermediate(NULL, '15/16');
1/2
(1 row)

-- test timeout
set statement_timeout = '3s';
select rational_intermediate('2147483646/2147483647'::rational, '1/1'::rational);
ERROR: canceling statement due to statement timeout
set statement_timeout to default;
4 changes: 4 additions & 0 deletions pg_rational.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "fmgr.h"
#include "access/hash.h"
#include "libpq/pqformat.h" /* send/recv functions */
#include "miscadmin.h"

#if PG_VERSION_NUM >= 110000
#include "common/int.h" /* portable overflow detection */
Expand Down Expand Up @@ -379,6 +380,9 @@ rational_intermediate(PG_FUNCTION_ARGS)

while (true)
{
/* Allow query cancel (e.g. Ctrl+C) and statement_timeout . */
CHECK_FOR_INTERRUPTS();

mediant(&lo, &hi, med);
if (cmp(med, &x) < 1)
memcpy(&lo, med, sizeof(Rational));
Expand Down
5 changes: 5 additions & 0 deletions sql/pg_rational_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,8 @@ select rational_intermediate('1/3', NULL);
select rational_intermediate('3/2', NULL);
-- though not the other direction
select rational_intermediate(NULL, '15/16');

-- test timeout
set statement_timeout = '3s';
select rational_intermediate('2147483646/2147483647'::rational, '1/1'::rational);
set statement_timeout to default;