title: python insert and update tstzranges with psycopg2
body: <p>Quick question about psycopg2 and ranges. Consider a postgresql table:</p>
  
  <pre><code>CREATE TABLE sensor(
    hostname varchar(64) NOT NULL, -- hostname of sensor
    ip varchar(15) NOT NULL,       -- ip of sensor
    period tstzrange NOT NULL,     -- valid range of sensor
    EXCLUDE USING gist (hostname WITH =, period with &amp;&amp;)
  );
  </code></pre>
  
  <p>where the below insert works</p>
  
  <pre><code>sql = "insert into sensor values (%s,%s,%s);"
  curs.execute(sql,(hostname,ip,'[%s,infinity]' % ts))
  </code></pre>
  
  <p>with hostname = socket.gethostname() ip='127.0.0.1' and ts is a isoformat timestamp i.e</p>
  
  <pre><code>dt.datetime.utcfromtimestamp(time.time()).isoformat()+"z"
  </code></pre>
  
  <p>This works but is there an easier/better way to manipulate ranges in postgresql with psycopg2 other than python string formatting? </p>
  
  <p>Additionally at some point I want to update the table with something like this</p>
  
  <pre><code>sql = "update sensor set period.upper = %s where hostname = %s and period.upper = infinity;"
  </code></pre>
  
  <p>I have not been able to find much documentation on psycopg2 support with ranges or perhaps I have not looked hard enough?</p>