-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_database.py
More file actions
38 lines (31 loc) · 1.02 KB
/
create_database.py
File metadata and controls
38 lines (31 loc) · 1.02 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 28 18:52:36 2022
@author: kdawg
"""
import psycopg2
from psycopg2 import Error
try:
connection = psycopg2.connect(user="kdawg",
password="",
host="127.0.0.1",
port="5432",
database="kdawg")
cursor = connection.cursor()
# SQL query to create a new table
create_table_query = '''CREATE TABLE patents
(ID INT PRIMARY KEY NOT NULL,
filename TEXT NOT NULL,
contents TEXT ); '''
# Execute a command: this creates a new table
cursor.execute(create_table_query)
connection.commit()
print("Table created successfully in PostgreSQL ")
except (Exception, Error) as error:
print("Error while connecting to PostgreSQL", error)
finally:
if connection:
cursor.close()
connection.close()
print("PostgreSQL connection is closed")