Postgresql Postgres将整数转换为时间

Postgresql Postgres将整数转换为时间,postgresql,Postgresql,我需要将以下(hh)整数列转换为时间列。预期结果如下: hh time 1 00:00 2 00:30 3 01:00 4 01:30 ... 48 23:30 你能帮忙吗? 另一种解决方案是使用unix时间戳: SELECT (to_timestamp((1 - 1) * 30 * 60) at time zone 'UTC')::time, (to_timestamp((2 - 1) * 30 * 60) at time z

我需要将以下(hh)整数列转换为时间列。预期结果如下:

hh     time
1      00:00
2      00:30
3      01:00
4      01:30
...
48     23:30
你能帮忙吗?

另一种解决方案是使用unix时间戳:

SELECT 
  (to_timestamp((1 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((2 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((3 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((4 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((5 - 1) * 30 * 60) at time zone 'UTC')::time,
  -- ...
  (to_timestamp((48 - 1) * 30 * 60) at time zone 'UTC')::time

另一种解决方案是使用unix时间戳:

SELECT 
  (to_timestamp((1 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((2 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((3 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((4 - 1) * 30 * 60) at time zone 'UTC')::time,
  (to_timestamp((5 - 1) * 30 * 60) at time zone 'UTC')::time,
  -- ...
  (to_timestamp((48 - 1) * 30 * 60) at time zone 'UTC')::time
您只需执行以下操作:

select hh, ('00:00:00'::time + (hh - 1) * interval '30 minute') as time
from t;
您只需执行以下操作:

select hh, ('00:00:00'::time + (hh - 1) * interval '30 minute') as time
from t;

这是48个半小时中的第4个半小时。
select(make_interval(分钟:=(hh-1)*30))::time这是48个半小时中的第4个半小时。
选择(make_interval(分钟:=(hh-1)*30))::时间