Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import psycopg2
- from faker import Faker
- # Connect to an existing database
- conn = psycopg2.connect(dbname="test", user="postgres", password="secret")
- # Open a cursor to perform database operations
- cur = conn.cursor()
- fake = Faker()
- for _ in range(0, 100000):
- adresa_sql = ("INSERT INTO Adresa (stlpec1, stlpec2, stlpec3) VALUES (%s, %s, %s) RETURNING id")
- cur.execute(adresa_sql, (faker.nieco(), faker.nieco(), faker.nieco()))
- adresa_id = cursor.fetchone()[0]
- zakaznik_sql = ("INSERT INTO Zakaznik (stlpec1, stlpec2, stlpec3) VALUES(%s, %s, %s)
- cur.execute(zakaznik_sql, (faker.nieco(), faker.nieco(), adresa_id))
- # Make the changes to the database persistent
- conn.commit()
- # Close communication with the database
- cur.close()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement