I am having trouble trying to make queries to a postgres db that is running in Docker.
As far as I can tell the database is connecting correctly using the psycopg2 library.
However when I execute a command and try to fetch the results, the results are empty. I can make the same query at the command line using psql and I get the expected results.
Can anyone help me figure out what I am doing wrong?
con = psycopg2.connect(
host= 'localhost',
port= '5432',
database= 'daystarr',
user= 'postgres',
password= 'admin',
)
print('Connected to Postgres Database')
cur = con.cursor()
cur.execute('SELECT * FROM tickets')
rows = cur.fetchall()
for r in rows:
print(r)
print(cur.fetchone())
cur.close()
con.close()
Here is the result when I run in command line:
cur.fetchall() returns nothing and cur.fetchone() returns None.
The other thing is that when I try to execute the command CREATE TABLE tickets (ticket_id INT PRIMARY KEY;)
I get a duplicate table error. So it must be connecting to the table. Thanks in advance!
Here is what it looks like when I just print(cur.fetchall()):


