簡體   English   中英

如何在 jsonb 列中基於 unix integer 設置 postgres 時間戳列?

[英]How to set a postgres timestamp column based on a unix integer in a jsonb column?

我正在嘗試更新我的數據庫以從 jsonb object 中提取 unix 紀元 integer 並使用該值設置時間戳列。 我有一些碎片,但我無法將它們全部組合在一起。 這就是我所在的位置(其中 subscription_end 是時間戳列,而 json_data 是 jsonb 列):

UPDATE "customers" SET "subscription_end" = to_timestamp(
    json_data -> 'some_property' ->> 'subscription_end'
);

我不確定我的所有東西是否都按正確的順序排列。 我找不到任何使用 to_timestamp function 和 json 鑽取的好例子,就像我在上面做的那樣。

就是這樣:

UPDATE "customers" SET "subscription_end" = 
    to_timestamp((json_data -> 'some_property' ->> 'subscription_end')::integer);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM