SQL Server Insert using SQLAlchemy in Python

I am trying to insert a table of 500 k rows into a SQL Server Database on a Streamlit app, it is deployed on Community Cloud.

When I do this on the app it does not take too much time however when 2 users do the insert (into different tables based of their username) the insert sometimes stops for one of the users.

I am not sure if this is due to Streamlit or the insert statement taking too much time, in any case here is the code:

note : uploadtable is the uploaded data in a pandas dataframe

if st.button("upload data"):    
    
# Construct the connection URL
    
    engine = create_engine(connection_url)
    
    # Create a metadata object
    metadata = MetaData()
    
    # Define your table structure
    submission = Table(username, metadata,
                    Column('id', String),
                    Column('premium', Float)
                    )


    metadata.create_all(engine)
    
    # Insert data from DataFrame into the SQL table
    uploadtable.to_sql(username, engine, if_exists='replace', index=False)
    st.write("Submission was uploaded")

Is there any way to speed this up or refine the code to be more efficient when multiple users does an insert?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.