CREATE OR REPLACE FUNCTION _time_to_integer(time with time zone)
RETURNS integer AS $$
SELECT
EXTRACT(HOUR FROM $1)::integer * 10000
+ EXTRACT(MINUTE FROM $1)::integer * 100
+ EXTRACT(SECONDS FROM $1)::integer
$$ IMMUTABLE STRICT LANGUAGE SQL;
DROP CAST IF EXISTS (time with time zone AS integer);
CREATE CAST (time with time zone AS integer)
WITH FUNCTION _time_to_integer (time with time zone)
AS IMPLICIT;