Skip to content

Instantly share code, notes, and snippets.

@Xifeng2009
Created January 8, 2019 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xifeng2009/6d2ca26a2d3a42554f1a7670f9db82d8 to your computer and use it in GitHub Desktop.
Save Xifeng2009/6d2ca26a2d3a42554f1a7670f9db82d8 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import psycopg2
conn = psycopg2.connect(database="testdb", user="postgres", password="pass123", host="127.0.0.1", port="5432")
print "Opened database successfully"
cur = conn.cursor()
cur.execute('''CREATE TABLE COMPANY
(ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL);''')
print "Table created successfully"
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment