title: fetchall method converting Postgresql timestamptz field to different timezone
body: <p>First question on here, so let me know if more information is needed. I am using the Python <code>psycopg2-binary==2.7.7</code> package in an attempt to pull PostgreSQL 9.6.11 timestamptz fields out of a database.</p>
  
  <p>With that said, the 'psycopg2' package seems to be coercing the timestamptz date-times to a different timezone than is present in the database. </p>
  
  <p>For instance, the following query will return the correct offset if run in a PostgreSQL client: </p>
  
  <p><strong>SQL</strong></p>
  
  <pre><code>SELECT row_to_json(t)
  FROM (
      SELECT '2019-01-24T08:24:00-05:00'::timestamptz AS tz 
  )t;
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>{"tz":"2019-01-24 08:24:00-05"}
  </code></pre>
  
  <p>However, if I run the same query via the <code>psycopg2.cursor.fetchall</code> method, I get a different offset than expected/returned: </p>
  
  <pre><code>import time
  import psycopg2
  import logging
  
  logger = logging.getLogger()
  
  
  def getRows(query, printRows=False, **kwargs):
      try:
          cs = "dbname={dbname} user={dbuser} password={dbpass} host={server} port={port}".format(
              **kwargs)
          con = psycopg2.connect(cs)
          con.set_session(readonly=True, autocommit=True)
      except Exception:
          logger.exception("--&gt;&gt;&gt;&gt;Something went wrong connecting to db")
          return None
  
      end = None
  
      try:
          start = time.time()
          cur = con.cursor()
          cur.execute(query)
  
          rows = cur.fetchall()
          if printRows:
              for i in rows:
                  print(i)
  
          cur.close()
          con.commit()
          con.close()
          end = time.time()
          logger.info(
              "--&gt;&gt;&gt;&gt;Query took {} seconds...".format(round(end - start, 2)))
          return rows
      except Exception:
          end = time.time()
          cur.close()
          con.commit()
          con.close()
          logger.exception("--&gt;&gt;&gt;&gt;Something went wrong with the query...")
          logger.info(
              "--&gt;&gt;&gt;&gt;Query took {} seconds...".format(round(end - start, 2)))
  
  
  if __name__ == '__main__':
      test = getRows("""SELECT row_to_json(t) AS "result" 
                        FROM(
                        SELECT '2019-01-24T08:24:00-05:00'::timestamptz AS tz
                        )t;
                     """, printRows=True, **DBSECRETS)
      print(test[0][0]) 
  </code></pre>
  
  <p><strong>Result</strong></p>
  
  <pre><code>{'tz': '2019-01-24T05:24:00-08:00'}
  </code></pre>
  
  <p>As seen above, the EST timezone (offset of <code>-5</code>)to PostgreSQL is being converted to a <code>-08:00</code> offset via the <code>psycopg2</code> package.</p>
  
  <p>I've checked the <code>psycopg2</code> documentation but could not find any conclusive examples to fix this issue. Specifically, I've checked here:</p>
  
  <p><a href="http://initd.org/psycopg/docs/cursor.html#cursor.tzinfo_factory" rel="nofollow noreferrer">http://initd.org/psycopg/docs/cursor.html#cursor.tzinfo_factory</a></p>