我想在 postgres 中将间隔转换为小数并需要这个结果?

I want to covert interval to decimal in postgres and need this result?

您好,我在 oracle 中有相同的查询

select ( TRUNC(b.pub_ts, 'MI') - DATE '1970-01-01')* 24 * 60 * 60, 
             TRUNC(b.pub_ts, 'MI') - DATE '1970-01-01'
                from abctable b  where b.blurb_id=344143

oracle中查询的输出是这样的

我已经在 postgres 中转换了查询,我想要相同的结果我怎么能得到它,我已经为 postgres 创建了查询但是它给出的是间隔而不是像 oracle 那样的十进制输出

 select  ( date_trunc('minute', b.pub_ts) - DATE '1970-01-01')* 24 * 60 * 60,
                              date_trunc('minute', b.pub_ts) - DATE '1970-01-01'
  FROM abc b WHERE b.blurb_id=344143;  

我已经尝试了很多解决方案。你能帮帮我吗

我觉得are is right, I think it is a duplicate of How do I convert an interval into a number of hours with postgres?

如果您检查已接受的答案,下面示例中唯一不同的是,我添加了 24 的除法。

SELECT EXTRACT(epoch FROM INTERVAL '1499990400 days 1206720:00:00')/24/60/60,
       EXTRACT(epoch FROM INTERVAL '17361 days 13:58:00')/24/60/60;

returns

1500040680 和 17361.581944444442

这正是您想要的值。

您的查询应大致如下:

SELECT
  extract( epoch FROM date_trunc('minute', b.pub_ts) - DATE '1970-01-01'),
  extract( epoch FROM date_trunc('minute', b.pub_ts) - DATE '1970-01-01')/86400
FROM abc b WHERE b.blurb_id=344143;