If your seconds column is a numeric
type, you can use this:
SELECT TO_CHAR((16200 || ' second')::interval, 'fmHH24hfmMIm')
If its a string
type, use this:
SELECT TO_CHAR('16200'::interval, 'fmHH24hfmMIm')
Of course, replace 16200 with your appropriate column name.
Precede HH and MI with fm
for Fill Mode. This will remove the preceding zero values from hour and minute.
Output:
4h30m
See Fiddle.
To get the SUM
of all values, add the SUM
function to your seconds column like so:
SELECT TO_CHAR(SUM(seconds_column::interval), 'fmHH24hfmMIm') FROM test_table
See Fiddle.