MCPcopy
hub / github.com/pandas-dev/pandas / to_sql

Method to_sql

pandas/io/sql.py:2844–2923  ·  view source on GitHub ↗

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, do no

(
        self,
        frame,
        name: str,
        if_exists: str = "fail",
        index: bool = True,
        index_label=None,
        schema=None,
        chunksize: int | None = None,
        dtype: DtypeArg | None = None,
        method: Literal["multi"] | Callable | None = None,
        engine: str = "auto",
        **engine_kwargs,
    )

Source from the content-addressed store, hash-verified

2842 return result
2843
2844 def to_sql(
2845 self,
2846 frame,
2847 name: str,
2848 if_exists: str = "fail",
2849 index: bool = True,
2850 index_label=None,
2851 schema=None,
2852 chunksize: int | None = None,
2853 dtype: DtypeArg | None = None,
2854 method: Literal["multi"] | Callable | None = None,
2855 engine: str = "auto",
2856 **engine_kwargs,
2857 ) -> int | None:
2858 """
2859 Write records stored in a DataFrame to a SQL database.
2860
2861 Parameters
2862 ----------
2863 frame: DataFrame
2864 name: string
2865 Name of SQL table.
2866 if_exists: {'fail', 'replace', 'append', 'delete_rows'}, default 'fail'
2867 fail: If table exists, do nothing.
2868 replace: If table exists, drop it, recreate it, and insert data.
2869 append: If table exists, insert data. Create if it does not exist.
2870 delete_rows: If a table exists, delete all records and insert data.
2871 index : bool, default True
2872 Write DataFrame index as a column
2873 index_label : string or sequence, default None
2874 Column label for index column(s). If None is given (default) and
2875 `index` is True, then the index names are used.
2876 A sequence should be given if the DataFrame uses MultiIndex.
2877 schema : string, default None
2878 Ignored parameter included for compatibility with SQLAlchemy
2879 version of ``to_sql``.
2880 chunksize : int, default None
2881 If not None, then rows will be written in batches of this
2882 size at a time. If None, all rows will be written at once.
2883 dtype : single type or dict of column name to SQL type, default None
2884 Optional specifying the datatype for columns. The SQL type should
2885 be a string. If all columns are of the same type, one single value
2886 can be used.
2887 method : {None, 'multi', callable}, default None
2888 Controls the SQL insertion clause used:
2889
2890 * None : Uses standard SQL ``INSERT`` clause (one per row).
2891 * 'multi': Pass multiple values in a single ``INSERT`` clause.
2892 * callable with signature ``(pd_table, conn, keys, data_iter)``.
2893
2894 Details and a sample callable implementation can be found in the
2895 section :ref:`insert method <io.sql.method>`.
2896 """
2897 if dtype:
2898 if not is_dict_like(dtype):
2899 # error: Value expression in dictionary comprehension has incompatible
2900 # type "Union[ExtensionDtype, str, dtype[Any], Type[object],
2901 # Dict[Hashable, Union[ExtensionDtype, Union[str, dtype[Any]],

Callers

nothing calls this directly

Calls 5

is_dict_likeFunction · 0.85
SQLiteTableClass · 0.85
itemsMethod · 0.45
createMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected