Re: [PATCH] Generate random dates/times in a specified range

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Greg Sabino Mullane <htamfids@gmail.com>
Cc: Dean Rasheed <dean.a.rasheed@gmail.com>, Damien Clochard <damien@dalibo.info>, pgsql-hackers@lists.postgresql.org
Date: 2025-07-15T15:10:42Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. doc: Improve description of new random(min, max) functions.

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

Greg Sabino Mullane <htamfids@gmail.com> writes:
> On Mon, Jul 14, 2025 at 3:21 AM Dean Rasheed <dean.a.rasheed@gmail.com>
> wrote:
>> Is it really worth adding a core function for that?

> Yes, I think it is. It is also trivial to get a random int from 50 to 100
> with
> 50 + floor(random() * 51)
> but random(50,100) is so much nicer.

I won't object to adding this for date/timestamp/timestamptz, but
I don't really believe that the time/timetz variants are worth the
code space.  I think the latter two would also have definitional
issues because of the modulo behavior of those types' underlying
arithmetic.

			regards, tom lane