polars.DataFrame.write_database#
- DataFrame.write_database(
- table_name: str,
- connection: str,
- *,
- if_table_exists: DbWriteMode = 'fail',
- engine: DbWriteEngine = 'sqlalchemy',
Write a polars frame to a database.
- Parameters:
- table_name
Schema-qualified 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_table_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 to use for writing frame data.
- Returns:
- int
The number of rows affected, if the driver provides this information. Otherwise, returns -1.