简体   繁体   English

没有时区的 PostgreSQL 时间

[英]PostgreSQL Time without timezone

I have a 3k data in my database and i would like to generate a random time for the column of operation_start and operation_end.我的数据库中有 3k 数据,我想为 operation_start 和 operation_end 列生成一个随机时间。

the code below is the one I'm using manually update each operation_start and operation_end下面的代码是我使用手动更新每个 operation_start 和 operation_end 的代码

UPDATE dashboard.inventory
SET operation_start = '1:00:43',
operation_end = '2:00:43',
update_date = NOW()
WHERE terminal_id = '01231238';

but updating all 3k data is a pain.但是更新所有 3k 数据很痛苦。 I tried googling but there seems to be no answer except for with datestamp我试过谷歌搜索,但似乎没有答案,除了日期戳

You can use time arithmetic.您可以使用时间算法。 However, this might be simpler in two steps because you seem to want the end time to be one hour after the start:但是,这可能分两个步骤更简单,因为您似乎希望结束时间是开始后一小时:

UPDATE dashboard.inventory
    SET operation_start = '00:00:00' + floor(random() * 23*60*60) * interval '1 second',
        update_date = NOW()
    WHERE terminal_id = '01231238';

UPDATE dashboard.inventory
    SET operation_end = operation_start + interval '1 hour'
    WHERE terminal_id = '01231238';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM