title: connected to psql docker container with psycopg2 but unable to read or write
body: <p>I'm trying to run a postgres db in a docker container, running a small python program with a class to call the db.</p>
  <p>When I run code with a query it seems to work fine, but gives no results.
  I can see that I in fact have hit the database because one of the tables have an id constraint, resulting in an error when I try to insert something that already exists.</p>
  <p>Using the db from TablePlus works fine.</p>
  <p>Code:</p>
  <pre><code>import psycopg2
  
  
  class postgres():
      def __init__(self, db=&quot;foo&quot;, user=&quot;bar&quot;, password='baz', host='127.0.0.1', port=5432):
          self.conn = psycopg2.connect(
              database=db, user=user, password=password, host=host, port=port)
          self.cur = self.conn.cursor()
  
      def query(self, query):
          self.cur.execute(query)
  
          # self.cur.execute(&quot;CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);&quot;)
  
      def close(self):
          self.cur.close()
          self.conn.close()
  
  
  db = postgres()
  db.query(&quot;INSERT INTO test (id) values('test2')&quot;)
  db.close()
  </code></pre>
  <p>results in:
  &quot;&quot;&quot;
  Traceback (most recent call last):
  File &quot;/Users/myname/projects/myproject/dataGathering/postgres.py&quot;, line 21, in 
  db.query(&quot;INSERT INTO test (id) values('test2')&quot;)
  File &quot;/Users/myname/projects/myproject/dataGathering/postgres.py&quot;, line 11, in query
  self.cur.execute(query)
  psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint &quot;id_pkey&quot;
  DETAIL:  Key (id)=(test) already exists.
  &quot;&quot;&quot;</p>
  <p>Inserting something without a conflicting id raises no error but neither gives any results in the db. SELECT queries have the same faith.</p>