diff options
| author | Peter Eisentraut | 2020-11-25 14:30:18 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2020-11-25 14:30:18 +0000 |
| commit | f73999262ed6c40d9a7c3d7cccec7143d4d15287 (patch) | |
| tree | b8f9d03bd2943346d96e7a70fa33816502e1030b /contrib/tablefunc/sql | |
| parent | 2fbd786c3446b1bc90f396d3fa5f4614b0a57d89 (diff) | |
tablefunc: Reject negative number of tuples passed to normal_rand()
The function converted the first argument i.e. the number of tuples to
return into an unsigned integer which turns out to be huge number when
a negative value is passed. This causes the function to take much
longer time to execute. Instead, reject a negative value.
(If someone really wants to generate many more result rows, they
should consider adding a bigint or numeric variant.)
While at it, improve SQL test to test the number of tuples returned by
this function.
Author: Ashutosh Bapat <ashutosh.bapat@2ndquadrant.com>
Discussion: https://www.postgresql.org/message-id/CAG-ACPW3PUUmSnM6cLa9Rw4BEC5cEMKjX8Gogc8gvQcT3cYA1A@mail.gmail.com
Diffstat (limited to 'contrib/tablefunc/sql')
| -rw-r--r-- | contrib/tablefunc/sql/tablefunc.sql | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/contrib/tablefunc/sql/tablefunc.sql b/contrib/tablefunc/sql/tablefunc.sql index ec375b05c63..02e8a98c73e 100644 --- a/contrib/tablefunc/sql/tablefunc.sql +++ b/contrib/tablefunc/sql/tablefunc.sql @@ -4,7 +4,9 @@ CREATE EXTENSION tablefunc; -- normal_rand() -- no easy way to do this for regression testing -- -SELECT avg(normal_rand)::int FROM normal_rand(100, 250, 0.2); +SELECT avg(normal_rand)::int, count(*) FROM normal_rand(100, 250, 0.2); +-- negative number of tuples +SELECT avg(normal_rand)::int, count(*) FROM normal_rand(-1, 250, 0.2); -- -- crosstab() |
