簡體   English   中英

沒有時區的 PostgreSQL 時間

[英]PostgreSQL Time without timezone

我的數據庫中有 3k 數據,我想為 operation_start 和 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';

但是更新所有 3k 數據很痛苦。 我試過谷歌搜索,但似乎沒有答案,除了日期戳

您可以使用時間算法。 但是,這可能分兩個步驟更簡單,因為您似乎希望結束時間是開始后一小時:

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