Skip to content

to_sql return inserted row count or list #23998

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

Closed
pmkroeker opened this issue Nov 29, 2018 · 4 comments · Fixed by #45137
Closed

to_sql return inserted row count or list #23998

pmkroeker opened this issue Nov 29, 2018 · 4 comments · Fixed by #45137
Labels
Enhancement IO SQL to_sql, read_sql, read_sql_query
Milestone

Comments

@pmkroeker
Copy link

Potential feature, could df.to_sql() return the indexes of the inserted rows? Something like knex.js Query Builder

inserted = df.to_sql(con=engine, name=example_table, if_exists='replace', index=False)

Problem description

This would allow for more quickly knowing how many rows have been entered from your dataframe

Expected Output

Something like inserted = 2 if 2 rows have been added. Even better would be inserted = [24, 25] where inserted is now a list of the inserted primary keys

@chris-b1
Copy link
Contributor

Would seem like we could return the sqlalchemy ResultProxy - answers those type of questions

from sqlalchemy import create_engine
eng = create_engine('sqlite://')
eng.execute("CREATE TABLE data (t TEXT)")

r = eng.execute("INSERT INTO data VALUES ('jane'), ('jon'), ('jack');")

r
# Out[72]: <sqlalchemy.engine.result.ResultProxy at 0x15a83128>
r.rowcount
# Out[73]: 3

@chris-b1 chris-b1 added API Design IO SQL to_sql, read_sql, read_sql_query labels Nov 29, 2018
@bobfang1992
Copy link

Is there any development towards this?

@selfcontrol7
Copy link

Looking forward.

@taiebnoe
Copy link

That'd be a nice feature!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants