HH:MM:SS Format

I need to add a column that is presented in minutes and present this value in the format HH:MM:sS to the user. Is there a way to transform this field into this format in Metabase? If I do this in SQL, the format is text type and I can't perform the sum.

I wrote the following custom expression to translate minutes to HH:MM:00. It's a bit pained as there is no text formatting function to zero-pad the digits, and no modulo operator. I also assumed the minutes are not fractional and seconds are always zero. It may be possible to handle fractional seconds if needed.

Tested on PostgreSQL 17.

concat(
  case(
    integer([duration] / 60) < 10,
    concat("0", text(floor([duration] / 60))),
    text(floor([duration] / 60))
  ),
  ":",
  case(
    integer([duration] - 60 * floor([duration] / 60)) <
      10,
    concat(
      "0",
      text(
        floor([duration] - 60 * floor([duration] / 60))
      )
    ),
    text(
      floor([duration] - 60 * floor([duration] / 60))
    )
  ),
  ":00"
)