【问题标题】:Convert ts field to seconds将 ts 字段转换为秒
【发布时间】:2017-10-03 09:44:43
【问题描述】:

我需要将 ts 字段转换为floating point number expressed in seconds

 |              ts               | user_id |   object_id |
 +-------------------------------+---------+-------------+
 | 2016-08-12 15:13:34.898779+01 |      12 |       5     | 

可以实现的格式相同
   import time
   ts = time.time()
   print ts #1507023571.12

所以,我的问题是如何转换 ts 字段?

【问题讨论】:

  • 能否请您在代码标签中也添加您预期的输出示例?
  • @RavinderSingh13 我需要使用 postgres 中的 ts 字段作为 zadd 中的 ts 字段。所以我正在寻找将被 redis 排序集接受的转换值。

标签: python sql python-2.7 postgresql


【解决方案1】:

使用epoch:

t=# select extract(epoch from now()), now();
    date_part     |              now
------------------+-------------------------------
 1507024254.74876 | 2017-10-03 09:50:54.748764+00
(1 row)

编辑

使用类似:select extract(epoch from ts) ts from reputation_log

【讨论】:

  • 谢谢。要对所有 ts 行进行此查询?不能像这样select extract(epoch from (select ts from reputation_log));
猜你喜欢
  • 1970-01-01
  • 2020-10-09
  • 2011-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-10
  • 2019-01-26
  • 2020-10-16
相关资源
最近更新 更多