text: -- truncate a timestamp float
  --
  create function iot.trunc_tz(
      tz timestamp with time zone,
      type text default 'unit'
  ) returns timestamp with time zone
  as $$
      select case
          when type='unit'
          then date_trunc('hour', tz) + date_part('minute', tz)::int / 2 * interval '2 min'
  
          when type='hourly'
          then date_trunc('hour', tz)
  
          else tz
      end
  $$ language sql stable;
  
  create function iot.trunc_ts(
      ts float,
      type text default 'unit'
  ) returns float as $$
      select trunc(extract(epoch from iot.trunc_tz(to_timestamp(ts), type)))::float
  $$ language sql stable;
  
  