[PATCH] Generate random dates/times in a specified range - Mailing list pgsql-hackers

From Damien Clochard
Subject [PATCH] Generate random dates/times in a specified range
Date
Msg-id f524d8cab5914613d9e624d9ce177d3d@dalibo.info
Whole thread Raw
Responses Re: [PATCH] Generate random dates/times in a specified range
List pgsql-hackers
Hello,

As I am involved in the PostgreSQL Anonymizer extension, I found that 
the random(min,max) functions introduced recently are very useful to 
generate synthetic data or define a masking policy.

I decided to submit a similar set of functions for random dates and 
times.

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

Each one returns a random date/time value t in the range min <= t <= 
max.

For the timetz function, a third parameter is required to define the 
timezone.
However if the value is an empty string, the session timezone is used.

These functions all rely on the pg_prng_int64_range function developped 
in
PG 17 for the random(bigint,bigint) function.

Regards,

-- 
Damien Clochard
Attachment

pgsql-hackers by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: Horribly slow pg_upgrade performance with many Large Objects
Next
From: "David G. Johnston"
Date:
Subject: Re: Should TRUNCATE fire DDL triggers