Re: [PATCH] Generate random dates/times in a specified range
Dean Rasheed <dean.a.rasheed@gmail.com>
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: Robert Treat <rob@xzilla.net>
Cc: Greg Sabino Mullane <htamfids@gmail.com>,
Damien Clochard <damien@dalibo.info>, Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@lists.postgresql.org
Date: 2025-07-15T07:04:32Z
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 →
-
doc: Improve description of new random(min, max) functions.
- 9c24111c4dad 19 (unreleased) landed
-
Add date and timestamp variants of random(min, max).
- faf071b55383 19 (unreleased) landed
On Tue, 15 Jul 2025 at 04:49, Robert Treat <rob@xzilla.net> wrote: > > On Mon, Jul 14, 2025 at 3:21 AM Dean Rasheed <dean.a.rasheed@gmail.com> wrote: > > > > But it's completely trivial to emulate random(min_date, max_date), just by doing > > > > min_date + random(0, max_date - min_date) > > > > Is it really worth adding a core function for that? > > I feel like this is a very similar argument against what was > ultimately the addition of timestamp based generate_series functions, > and similarly I think adding these in would be a rather useful > improvement for users, though like generate_series, we don't need to > hit every different data type (no one should ever generate a random > timetz for instance). Right, and for generate_series() we didn't add a variant for type date. In fact, we explicitly documented how a sequence of dates can be generated using the date-plus-integer operator. In fact, I think generate_series() sets a good precedent, and I could get behind a proposal that adds new random() functions with the same signatures as the timestamp-based generate_series() functions. In particular, I think that it's quite likely that if I wanted a random timestamp in some range, I would want some specified precision, like say 'hour' or 'day', and not a timestamp with some random number of microseconds. (In a similar vein, it might be useful to add an optional "step" parameter to the random integer/numeric functions, but that's really a separate proposal.) Regards, Dean