Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support copyfrom #63

Open
borissmidt opened this issue Nov 21, 2024 · 0 comments
Open

support copyfrom #63

borissmidt opened this issue Nov 21, 2024 · 0 comments

Comments

@borissmidt
Copy link

To insert mutliple values at once there is the sqlc copyfrom, but it it is unsupported in sqlc-gen-python

But it should be quite easy to implement using an executemany statement:
https://stackoverflow.com/questions/13020908/sql-multiple-inserts-with-python

rows = []

for row in range(sheet.nrows):
    """name is in the 0th col. email is the 4th col."""
    name = sheet.cell(row, 0).value  
    email =  sheet.cell(row, 4).value
    rows.append((name, email))

db = MySQLdb.connect(host=host, user=user, db=dbname, passwd=pwd)
cursor = db.cursor()
cursor.executemany("""INSERT INTO mailing_list (name,email) VALUES (%s,%s)""", rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant