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: Damien Clochard <damien@dalibo.info>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2025-07-09T22:14: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).

Damien Clochard <damien@dalibo.info> writes:
> So this adds 5 new variants of the random() function:

>      random(min date, max date) returns date
>      random(min time, max time) returns time
>      random(min time, max time, zone text) returns timetz
>      random(min timestamp, max timestamp) returns timestamp
>      random(min timestamptz, max timestamptz) returns timestamptz

I'm a little uncomfortable with this proposal, mainly because it
overloads the random() function name to the point where I'm afraid
of "ambiguous function" failures in SQL code that used to be fine.

The traditional way of achieving these results would be something like

    select now() + random() * interval '10 days';

and I'm not convinced that the use-case is so large as to justify
adding built-in forms of that.

			regards, tom lane