В Postgres, как я могу округлить возвращение экстрактной эпохи - PullRequest
0 голосов
/ 05 марта 2020

psql (9.6.7, сервер 11.3) на linux

Учитывая эту простую таблицу ...

dvdb=> select * from delme;
        start_dt        |         end_dt         
------------------------+------------------------
 2020-03-01 00:00:00-05 | 2020-03-03 12:34:56-05
(1 row)

Я хочу количество часов, округленное до ближайшая десятая часа времени дельты. Я могу зайти так далеко ...

dvdb=> select extract(epoch from age(end_dt,start_dt)/3600) from delme;
 date_part 
-----------
 60.582222
(1 row)

Но, кажется, не могу округлить ....

dvdb=> select round(extract(epoch from age(end_dt,start_dt)/3600),1) from delme;
ERROR:  function round(double precision, integer) does not exist
LINE 1: select round(extract(epoch from age(end_dt,start_dt)/3600),1...
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
dvdb=> 


dvdb=> select round(cast(extract(epoch from age(end_dt,start_dt)/3600) as float),1) from delme;
ERROR:  function round(double precision, integer) does not exist
LINE 1: select round(cast(extract(epoch from age(end_dt,start_dt)/36...
           ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
dvdb=> 

Я думаю, что я не правильно понимаю раунд, введите его хочет за первый аргумент ...

dvdb=> select round(123.456,1);
 round 
-------
 123.5
(1 row)

dvdb=> select round(cast(123.456 as float),1);
ERROR:  function round(double precision, integer) does not exist
LINE 1: select round(cast(123.456 as float),1);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
dvdb=> 

1 Ответ

1 голос
/ 05 марта 2020

Мне кажется, я понял ...

dvdb=> select round(cast(extract(epoch from age(end_dt,start_dt)/3600) as numeric),1) from delme;
 round 
-------
  60.6
(1 row)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...