Last active
September 19, 2020 15:29
-
-
Save schnipdip/4d3b5cf8e7b712f8f9e4e33f67be5a0e to your computer and use it in GitHub Desktop.
Creating a #Postgresql Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psycopg2 | |
def create_table(): | |
#Referece: Constructing #Postgresql connection obect | |
sql_create_asset_table = ('''CREATE TABLE IF NOT EXISTS ASSETS ( | |
ID SERIAL PRIMARY KEY, | |
NAME TEXT NOT NULL, | |
LICENSE TEXT NOT NULL, | |
QUANTITY INT NOT NULL, | |
HOSTNAME TEXT NOT NULL, | |
EXPIRES TEXT NOT NULL, | |
ENVIRONMENT TEXT NOT NULL, | |
DESCRIPTION TEXT NOT NULL);''') | |
cursor.execute(sql_create_asset_table) | |
#Commit Changes to Database | |
conn.commit() | |
#Close Database Connection | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment