27 lines
538 B
Python
27 lines
538 B
Python
#!/usr/bin/env python3
|
|
|
|
# https://www.postgresqltutorial.com/postgresql-python/connect/
|
|
|
|
import psycopg
|
|
from config import config
|
|
|
|
conn = None
|
|
|
|
try:
|
|
params = config()
|
|
conn = psycopg.connect(**params)
|
|
cur = conn.cursor()
|
|
cur.execute(
|
|
"SELECT * from main LIMIT 10"
|
|
)
|
|
# cur.fetchone()
|
|
for record in cur:
|
|
print(record)
|
|
conn.commit()
|
|
cur.close()
|
|
except (Exception, psycopg.DatabaseError) as error:
|
|
print(error)
|
|
finally:
|
|
if conn is not None:
|
|
conn.close()
|
|
|