Skip to content

Instantly share code, notes, and snippets.

@schnipdip
Last active September 19, 2020 15:29
Show Gist options
  • Save schnipdip/4d3b5cf8e7b712f8f9e4e33f67be5a0e to your computer and use it in GitHub Desktop.
Save schnipdip/4d3b5cf8e7b712f8f9e4e33f67be5a0e to your computer and use it in GitHub Desktop.
Creating a #Postgresql Table
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