import psycopg as pg
import time

# Connect to an existing QuestDB instance

conn_str = 'user=admin password=quest host= port=8812 dbname=qdb'
with pg.connect(conn_str, autocommit=True) as connection:

# Open a cursor to perform database operations

with connection.cursor() as cur:

#Query the database and obtain data as Python objects.

cur.execute('SELECT * FROM trades_pg;')
records = cur.fetchall()
for row in records:

# the connection is now closed