title: Sqlalchemy representation for custom postgres range type
body: <p>I have the need for a custom range type. I am trying to represent an hourly range. For each day of the week a range (datetime.time, datetime.time) rather than separate TIME columns, I would like to have access to Postgres/sqlalchemy range operators if possible.</p>
  
  <p>I'm looking for something like TSRANGE but hours instead of the normal (datetime.datetime, datetime.datetime)</p>
  
  <p>In postgres itself this works wonderfully. For example.</p>
  
  <pre><code>create type timerange as range (subtype = time);
  
  create table schedule 
  (
    id integer not null primary key,
    time_range timerange
  );
  
  insert into schedule 
  values
  (1, timerange(time '08:00', time '10:00', '[]')),
  (2, timerange(time '10:00', time '12:00', '[]'));
  
  select *
  from schedule
  where time_range @&gt; time '09:00'
  </code></pre>
  
  <p>So here is the question. How do I represent this custom type I have created in Postgres in SQLAlchemy? Subclass TSRANGE, TypeDecorator on TIME, or possibly create a new SQLALchemy UserDefinedType. I am not quite sure which way to go. Any suggestions would be much appreciated. Thanks!</p>