You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

19 lines
723 B

  1. import psycopg2
  2. from faker import Faker
  3. # https://stackabuse.com/working-with-postgresql-in-python/
  4. con = psycopg2.connect(database="week08", user="postgres",
  5. password="postgres", host="127.0.0.1", port="5432")
  6. print("Database opened successfully")
  7. cur = con.cursor()
  8. cur.execute('''CREATE TABLE CUSTOMER
  9. (ID INT PRIMARY KEY NOT NULL,
  10. Name TEXT NOT NULL,
  11. Address TEXT NOT NULL,
  12. review TEXT);''')
  13. print("Table created successfully")
  14. fake = Faker()
  15. for i in range(10000):
  16. cur.execute("INSERT INTO CUSTOMER (ID,Name,Address,review) VALUES ('"+ str(i)+"','"+fake.name()+"','"+fake.address()+"','"+fake.text()+"')")
  17. con.commit()