Write records stored in a DataFrame to a SQL database. Parameters ---------- frame : DataFrame name : string Name of SQL table. if_exists : {'fail', 'replace', 'append', 'delete_rows'}, default 'fail' - fail: If table exists,
(
self,
frame,
name: str,
if_exists: Literal["fail", "replace", "append", "delete_rows"] = "fail",
index: bool = True,
index_label=None,
schema: str | None = None,
chunksize: int | None = None,
dtype: DtypeArg | None = None,
method: Literal["multi"] | Callable | None = None,
engine: str = "auto",
**engine_kwargs,
)
| 1962 | ) |
| 1963 | |
| 1964 | def to_sql( |
| 1965 | self, |
| 1966 | frame, |
| 1967 | name: str, |
| 1968 | if_exists: Literal["fail", "replace", "append", "delete_rows"] = "fail", |
| 1969 | index: bool = True, |
| 1970 | index_label=None, |
| 1971 | schema: str | None = None, |
| 1972 | chunksize: int | None = None, |
| 1973 | dtype: DtypeArg | None = None, |
| 1974 | method: Literal["multi"] | Callable | None = None, |
| 1975 | engine: str = "auto", |
| 1976 | **engine_kwargs, |
| 1977 | ) -> int | None: |
| 1978 | """ |
| 1979 | Write records stored in a DataFrame to a SQL database. |
| 1980 | |
| 1981 | Parameters |
| 1982 | ---------- |
| 1983 | frame : DataFrame |
| 1984 | name : string |
| 1985 | Name of SQL table. |
| 1986 | if_exists : {'fail', 'replace', 'append', 'delete_rows'}, default 'fail' |
| 1987 | - fail: If table exists, do nothing. |
| 1988 | - replace: If table exists, drop it, recreate it, and insert data. |
| 1989 | - append: If table exists, insert data. Create if does not exist. |
| 1990 | - delete_rows: If a table exists, delete all records and insert data. |
| 1991 | index : boolean, default True |
| 1992 | Write DataFrame index as a column. |
| 1993 | index_label : string or sequence, default None |
| 1994 | Column label for index column(s). If None is given (default) and |
| 1995 | `index` is True, then the index names are used. |
| 1996 | A sequence should be given if the DataFrame uses MultiIndex. |
| 1997 | schema : string, default None |
| 1998 | Name of SQL schema in database to write to (if database flavor |
| 1999 | supports this). If specified, this overwrites the default |
| 2000 | schema of the SQLDatabase object. |
| 2001 | chunksize : int, default None |
| 2002 | If not None, then rows will be written in batches of this size at a |
| 2003 | time. If None, all rows will be written at once. |
| 2004 | dtype : single type or dict of column name to SQL type, default None |
| 2005 | Optional specifying the datatype for columns. The SQL type should |
| 2006 | be a SQLAlchemy type. If all columns are of the same type, one |
| 2007 | single value can be used. |
| 2008 | method : {None', 'multi', callable}, default None |
| 2009 | Controls the SQL insertion clause used: |
| 2010 | |
| 2011 | * None : Uses standard SQL ``INSERT`` clause (one per row). |
| 2012 | * 'multi': Pass multiple values in a single ``INSERT`` clause. |
| 2013 | * callable with signature ``(pd_table, conn, keys, data_iter)``. |
| 2014 | |
| 2015 | Details and a sample callable implementation can be found in the |
| 2016 | section :ref:`insert method <io.sql.method>`. |
| 2017 | engine : {'auto', 'sqlalchemy'}, default 'auto' |
| 2018 | SQL engine library to use. If 'auto', then the option |
| 2019 | ``io.sql.engine`` is used. The default ``io.sql.engine`` |
| 2020 | behavior is 'sqlalchemy' |
| 2021 |
nothing calls this directly
no test coverage detected