-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_table.py
42 lines (32 loc) · 920 Bytes
/
create_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import psycopg2
def create_tables():
commands = (
"""
CREATE TABLE IF NOT EXISTS user_swear_count (
id SERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL,
swear_count INT NOT NULL,
detected_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
)
""",
)
conn = None
try:
conn = psycopg2.connect(
host="postgres-server",
database="slang",
user="postgres",
password="#############",
port = '5432')
cur = conn.cursor()
for command in commands:
cur.execute(command)
cur.close()
conn.commit()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
if __name__ == '__main__':
create_tables()