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

Mock commit statement for open-mysql-db by using panda dataframe #3850

Open
tobegit3hub opened this issue Apr 7, 2024 · 0 comments
Open
Assignees

Comments

@tobegit3hub
Copy link
Collaborator

Describe the feature you'd like

Now we are using sqlalchemy and pandas dataframe. The method of "to_sql" is not supported which uses commit statements.

Here is the example code.

import pandas as pd
from sqlalchemy import create_engine

# Create a Pandas DataFrame (replace this with your actual data)
data = {'id': [1, 2, 3],
        'name': ['Alice', 'Bob', 'Charlie'],
        'age': [25, 30, 35]}
df = pd.DataFrame(data)

# Create a MySQL database engine using SQLAlchemy
engine = create_engine('mysql://username:password@host/db_name')

# Replace 'username', 'password', 'host', and 'db_name' with your actual database credentials

# Define the name of the table in the database where you want to write the data
table_name = 'your_table_name'

# Write the DataFrame 'df' into the MySQL table
df.to_sql(table_name, engine, if_exists='replace', index=False)

# 'if_exists' parameter options:
# - 'fail': If the table already exists, an error will be raised.
# - 'replace': If the table already exists, it will be replaced.
# - 'append': If the table already exists, data will be appended to it.

print("Data written to MySQL table successfully!")

And we may get the error like this.

[1002] create logic plan tree failed--Un-support statement type: CommitStatement'

Additional context

Add any other context or screenshots about the feature request here.

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

2 participants