Is there a way to save Polars DataFrame into a database, MS SQL for example?
ConnectorX library doesn’t seem to have that option.
Is there a way to save Polars DataFrame into a database, MS SQL for example?
ConnectorX library doesn’t seem to have that option.
Polars doesen't support direct writing to a database. You can proceed in two ways:
Polars exposes the write_database
method on the DataFrame
class.
Using polars 0.20.5 `write_database` for sqlite3 always returns an error. On the other hand, `read_database` works well. Sample code: import sqlite3 import polars as pl conn = sqlite3.connect("test.db" ) #this code works well. pl.read_database( query='SELECT * FROM table', connection = conn , ) #this code makes error df_insertdata.write_database( table_name = "table", connection = conn, ) From [the polars web site] polars.DataFrame.write_database https://docs.pola.rs/py-polars/html/reference/api/polars.DataFrame.write_database.html#polars.DataFrame.write_databasel:
Polars doesen't support direct writing to a database. You can proceed in two ways:
© 2022 - 2025 — McMap. All rights reserved.
df.to_pandas().to_sql(...)
for now. – Overfeedpolars>=0.16.10
you can usedf.write_database()
method. – Noted