且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PostgreSQL Oracle 兼容性之 - round interval

更新时间:2022-06-13 04:38:18

标签

PostgreSQL , Oracle , interval , 数值 , 转换


背景

Oracle 可以将interval当成一个秒为单位的数值,并允许对其值进行round。

PostgreSQL的round没有写这个,不过我们可以自定义一个兼容函数。

create or replace function round(interval, int) returns float8 as $$  
  select round(EXTRACT(EPOCH FROM $1)::numeric, $2)::float8;  
$$ language sql strict immutable;  
postgres=# select round(interval '1h 10min 1.1second',2);  
 round    
--------  
 4201.1  
(1 row)  

PostgreSQL大量时间操作函数在这里可以知道到

https://www.postgresql.org/docs/current/static/functions-datetime.html

参考

https://www.postgresql.org/docs/current/static/functions-datetime.html

https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions103.htm

《PostgreSQL Oracle 兼容性 之 NUMTODSINTERVAL》