Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import psycopg2
  2. from faker import Faker
  3.  
  4. # Connect to an existing database
  5. conn = psycopg2.connect(dbname="test", user="postgres", password="secret")
  6.  
  7. # Open a cursor to perform database operations
  8. cur = conn.cursor()
  9.  
  10. fake = Faker()
  11. for _ in range(0, 100000):
  12.     adresa_sql = ("INSERT INTO Adresa (stlpec1, stlpec2, stlpec3) VALUES (%s, %s, %s) RETURNING id")
  13.     cur.execute(adresa_sql, (faker.nieco(), faker.nieco(), faker.nieco()))
  14.     adresa_id = cursor.fetchone()[0]
  15.  
  16.     zakaznik_sql = ("INSERT INTO Zakaznik (stlpec1, stlpec2, stlpec3) VALUES(%s, %s, %s)
  17.     cur.execute(zakaznik_sql, (faker.nieco(), faker.nieco(), adresa_id))
  18.  
  19. # Make the changes to the database persistent
  20. conn.commit()
  21.  
  22. # Close communication with the database
  23. cur.close()
  24. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement