psycopg2でpostgreSQLに繋ぐ
psycogp2のinstall
venvを使った
$ pip install psycopg2
接続とSQLの実行
code:py
import psycopg2
user = "USER_NAME" #user nameを入力 host = "localhost"
port = "5432"
dbname = "postgres"
connector =psycopg2.connect(f'postgresql://{user}:{password}@{host}:{port}/{dbname}')
cursor = connector.cursor()
# cursor.execute("SELECT version();")
cursor.execute("SELECT * FROM Shohin;")
result = cursor.fetchall()
print(result)