polars.DataFrame.write_database#

DataFrame.write_database(
table_name: str,
connection: str,
*,
if_exists: DbWriteMode = 'fail',
engine: DbWriteEngine = 'sqlalchemy',
) None[source]#

Write a polars frame to a database.

Parameters:
table_name

Name of the table to create or append to in the target SQL database. If your table name contains special characters, it should be quoted.

connection

Connection URI string, for example:

  • “postgresql://user:pass@server:port/database”

  • “sqlite:////path/to/database.db”

if_exists{‘append’, ‘replace’, ‘fail’}

The insert mode. ‘replace’ will create a new database table, overwriting an existing one. ‘append’ will append to an existing table. ‘fail’ will fail if table already exists.

engine{‘sqlalchemy’, ‘adbc’}

Select the engine used for writing the data.