psycopg2 を利用して PostgreSQL に接続する
import numpy as np
import psycopg2 as pg
import psycopg2.extras
connection = pg.connect("host=localhost port=5432 dbname=db_name user=postgres")
cursor = connection.cursor(cursor_factory=psycopg2.extras.DictCursor)
cursor.execute("SELECT * FROM users")
results = cursor.fetchall()
values = []
for row in results:
values.append(dict(row))
print(values)
cursor.close()
connection.close()