| From: | Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
|---|---|
| To: | Robert Treat <rob(at)xzilla(dot)net> |
| Cc: | Greg Sabino Mullane <htamfids(at)gmail(dot)com>, Damien Clochard <damien(at)dalibo(dot)info>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: [PATCH] Generate random dates/times in a specified range |
| Date: | 2025-07-15 07:04:32 |
| Message-ID: | CAEZATCWugZ5PESq10TJCQUgs68S2aLhSzdgMNuiLSmNqd7R5sQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, 15 Jul 2025 at 04:49, Robert Treat <rob(at)xzilla(dot)net> wrote:
>
> On Mon, Jul 14, 2025 at 3:21 AM Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joel Jacobson | 2025-07-15 07:20:58 | Re: Optimize LISTEN/NOTIFY |
| Previous Message | Maxim Orlov | 2025-07-15 06:23:37 | Re: Add 64-bit XIDs into PostgreSQL 15 |