23 lines
548 B
Python
23 lines
548 B
Python
import psycopg2
|
|
|
|
try:
|
|
conn = psycopg2.connect(
|
|
dbname="kolchin",
|
|
user="kolchin",
|
|
password="postgres",
|
|
host="pg",
|
|
port="5432"
|
|
)
|
|
except:
|
|
print('Can`t establish connection to database')
|
|
#print(conn)
|
|
|
|
cursor = conn.cursor()
|
|
|
|
cursor.execute('CREATE TABLE IF NOT EXISTS tablee(name varchar(10) NOT NULL,surname varchar,city varchar,age smallint);')
|
|
|
|
conn.commit()
|
|
cursor.close() # закрываем курсор
|
|
conn.close() # закрываем соединение
|
|
|