Python: PostgreSQL

 

connection

import psycopg2
from psycopg2 import Error, connection, cursor

conn: connection | None = None
c1: cursor | None = None

try:
    conn = psycopg2.connect(host='localhost', port=5432, user='postgres',
                            password='postgres', database='entail')
    c1 = conn.cursor()
    print(conn.get_dsn_parameters())
    c1.execute('select version()')
    print(c1.fetchall())
except (Exception, Error) as e:
    print(e)
finally:
    if connection and not connection.closed:
        if not c1.closed:
            c1.close()
        conn.close()

 

create table

 

posted @ 2023-04-29 21:47  ascertain  阅读(13)  评论(0编辑  收藏  举报