How to write bigint (timestamp in milliseconds) value as timestamp in postgresql

后端 未结 3 1710
再見小時候
再見小時候 2021-02-07 10:44

I\'m trying to store in timestamp with timezone field my value. It is in milliseconds from 1970.

select TO_CHAR(TO_TIMESTAMP(1401432881230), \'DD/MM/YYYY HH24:MI:S

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 10:51

    Okay, I understood. My INSERT should looks like:

    INSERT INTO events (timestamp) VALUES (to_timestamp(TO_CHAR(TO_TIMESTAMP(1401432881222 / 1000), 'YYYY-MM-DD HH24:MI:SS') || '.' || (1401432881222%1000), 'YYYY-MM-DD HH24:MI:SS.MS'))

    I'm converting bigint-timestamp with milliseconds to text with required format ('YYYY-MM-DD HH24:MI:SS.MS') and pass it to to_timestamp function.

提交回复
热议问题