Add date and timestamp variants of random(min, max).
authorDean Rasheed <dean.a.rasheed@gmail.com>
Tue, 9 Sep 2025 09:39:30 +0000 (10:39 +0100)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Tue, 9 Sep 2025 09:39:30 +0000 (10:39 +0100)
commitfaf071b553830d39fc583beabcaf56ed65259acc
tree5ebd4632f87ab9df03cf59492825d4fda9198be6
parent5ac3c1ac22cb325844d0bee37f79f2c11931b32e
Add date and timestamp variants of random(min, max).

This adds 3 new variants of the random() function:

    random(min date, max date) returns date
    random(min timestamp, max timestamp) returns timestamp
    random(min timestamptz, max timestamptz) returns timestamptz

Each returns a random value x in the range min <= x <= max.

Author: Damien Clochard <damien@dalibo.info>
Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Reviewed-by: Vik Fearing <vik@postgresfriends.org>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/f524d8cab5914613d9e624d9ce177d3d@dalibo.info
doc/src/sgml/func/func-datetime.sgml
doc/src/sgml/func/func-math.sgml
src/backend/utils/adt/pseudorandomfuncs.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/test/regress/expected/random.out
src/test/regress/sql/random.sql