# Instructions for saving to SQL?

**URL:** https://community.plotly.com/t/instructions-for-saving-to-sql/71494
**Category:** Dash Python
**Created:** [January 10, 2023, 7:09pm UTC](https://community.plotly.com/t/instructions-for-saving-to-sql/71494 "2023-01-10T19:09:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)
#### Post date: [January 10, 2023, 7:09pm UTC](https://community.plotly.com/t/instructions-for-saving-to-sql/71494/1 "2023-01-10T19:09:49Z")

</div>

Could anyone share with me information they found useful for learning how to take inputs from Dash and save to a SQL database. The database structure has already been created.

Thanks!

---

<div class="post-metadata">

### Author: ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)
#### Post date: [January 10, 2023, 7:32pm UTC](https://community.plotly.com/t/instructions-for-saving-to-sql/71494/2 "2023-01-10T19:32:06Z")

</div>

Hello @bpolasek,

There are a few ways:

You can save a dataframe directly to sql using df.to\_sql.  
[https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to\_sql.html](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_sql.html)

You can hook up to PostgreSQL and push updates that way:

> [@How to power a Dash App with a PostgreSQL DB](https://community.plotly.com/t/how-to-power-a-dash-app-with-a-postgresql-db/71460):
>
> Hi there, in this article I will go through the steps to set up a database (db) on your Heroku project, the ‘musts’ to consider to make a connection to a bd manager and the deployment of a dash-app capable to commit data to the database. This tutorial is tied to a multi-page Dash app that I built and shared with you in this [GitHub repository](https://github.com/alan-navarro/street_team.git). However, the focus of this article will be on connecting a Dash app to a PostgreSQL Database, so even if you have a one page Dash app, this will show you …

Or, if you want transactions and SQL strings, you can use a library like [pyodbc](https://github.com/mkleehammer/pyodbc/wiki).

I personally use the last option, as I do some pretty extensive updates to a SQL server.

---

<div class="post-metadata">

### Author: ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)
#### Post date: [January 10, 2023, 7:36pm UTC](https://community.plotly.com/t/instructions-for-saving-to-sql/71494/3 "2023-01-10T19:36:03Z")

</div>

Yeah so I have been reading in data from a SQL database to generate graphs. Now I need to save some settings from these graphs into different SQL database tables. The current SQL set up uses pyodbc so I’m sure that is probably what I need to go for here.

---

<div class="post-metadata">

### Author: ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)
#### Post date: [January 10, 2023, 7:39pm UTC](https://community.plotly.com/t/instructions-for-saving-to-sql/71494/4 "2023-01-10T19:39:23Z")

</div>

In that case, you can create a cursor and perform an execute a raw SQL could with your updates.

Remember, do not take user’s inputs directly, but use ? as a placeholder.

Also, do not forget to commit after you are done. 🙂

---

<div class="post-metadata">

### Author: ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)
#### Post date: [January 10, 2023, 7:40pm UTC](https://community.plotly.com/t/instructions-for-saving-to-sql/71494/5 "2023-01-10T19:40:25Z")

</div>

Thank you!
