ALTER TABLE
aabb ALTER id
SET
DEFAULT concat(
to_date ('2019-07-22', 'yyyy-MM-dd') - floor((random() * 25)) :: int,
' ',
make_time(
floor((random() * 12)) :: int,
floor((random() * 60)) :: int,
floor((random() * 60)) :: int
)
) :: timestamp without time zone
像插入序列一样先给aabb表的id字段添加随机时间段,以上示例是2019年7月22日到往前推25天的随机时间
ALTER TABLE
aabb ALTER id
SET
DEFAULT concat(
to_date ('2019-07-22', 'yyyy-MM-dd') - floor((random() * 365)) :: int,
' ',
make_time(
floor((random() * 12)) :: int,
floor((random() * 60)) :: int,
floor((random() * 60)) :: int
)
) :: timestamp without time zone
时间范围可以通过第一个random调节,以上是365天范围内时间
如下图所示为结果