pgsql: Add date and timestamp variants of random(min, max).

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add date and timestamp variants of random(min, max).
Date: 2025-09-09 09:48:46
Message-ID: E1uvuxy-001Fry-2G@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)dalibo(dot)info>
Reviewed-by: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Reviewed-by: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Reviewed-by: Vik Fearing <vik(at)postgresfriends(dot)org>
Reviewed-by: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Discussion: https://postgr.es/m/f524d8cab5914613d9e624d9ce177d3d@dalibo.info

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/faf071b553830d39fc583beabcaf56ed65259acc

Modified Files
--------------
doc/src/sgml/func/func-datetime.sgml | 30 +++++++++
doc/src/sgml/func/func-math.sgml | 3 +-
src/backend/utils/adt/pseudorandomfuncs.c | 104 +++++++++++++++++++++++++++---
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 12 ++++
src/test/regress/expected/random.out | 87 +++++++++++++++++++++++++
src/test/regress/sql/random.sql | 26 ++++++++
7 files changed, 254 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2025-09-09 13:42:13 pgsql: Fix typo in comment
Previous Message Amit Kapila 2025-09-09 03:28:52 pgsql: Fix Coverity issue reported in commit a850be2fe.