Guest User

Untitled

a guest
Feb 20th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # On Windows
  2. py -3 -m venv venv
  3. source venv/Scripts/activate
  4. # On Linux
  5. $ python3 -m venv venv;
  6. $ source venv/bin/activate
  7.  
  8. pip install psycopg2
  9.  
  10. import psycopg2
  11.  
  12. password postgres
  13.  
  14. password <user_name>
  15.  
  16. con = psycopg2.connect('dbname='testdb' user='postgres' host='localhost' password='my_password')
  17.  
  18. cur = con.cursor()
  19.  
  20. cur.execute("CREATE TABLE test(id serial PRIMARY KEY, name varchar, email varchar)")
  21.  
  22. cur.execute("SELECT * FROM test")
  23. items = cur.fetchall()
  24.  
  25. con.commit()
  26.  
  27. cur.close()
  28. con.close()
Add Comment
Please, Sign In to add comment