MCPcopy Create free account
hub / github.com/dask/dask / to_sql

Function to_sql

dask/dataframe/io/sql.py:425–604  ·  view source on GitHub ↗

Store Dask Dataframe to a SQL table An empty table is created based on the "meta" DataFrame (and conforming to the caller's "if_exists" preference), and then each block calls pd.DataFrame.to_sql (with `if_exists="append"`). Databases supported by SQLAlchemy [1]_ are supported. Tables c

(
    df,
    name: str,
    uri: str,
    schema=None,
    if_exists: str = "fail",
    index: bool = True,
    index_label=None,
    chunksize=None,
    dtype=None,
    method=None,
    compute=True,
    parallel=False,
    engine_kwargs=None,
)

Source from the content-addressed store, hash-verified

423
424
425def to_sql(
426 df,
427 name: str,
428 uri: str,
429 schema=None,
430 if_exists: str = "fail",
431 index: bool = True,
432 index_label=None,
433 chunksize=None,
434 dtype=None,
435 method=None,
436 compute=True,
437 parallel=False,
438 engine_kwargs=None,
439):
440 """Store Dask Dataframe to a SQL table
441
442 An empty table is created based on the "meta" DataFrame (and conforming to the caller's "if_exists" preference), and
443 then each block calls pd.DataFrame.to_sql (with `if_exists="append"`).
444
445 Databases supported by SQLAlchemy [1]_ are supported. Tables can be
446 newly created, appended to, or overwritten.
447
448 Parameters
449 ----------
450 name : str
451 Name of SQL table.
452 uri : string
453 Full sqlalchemy URI for the database connection
454 schema : str, optional
455 Specify the schema (if database flavor supports this). If None, use
456 default schema.
457 if_exists : {'fail', 'replace', 'append'}, default 'fail'
458 How to behave if the table already exists.
459
460 * fail: Raise a ValueError.
461 * replace: Drop the table before inserting new values.
462 * append: Insert new values to the existing table.
463
464 index : bool, default True
465 Write DataFrame index as a column. Uses `index_label` as the column
466 name in the table.
467 index_label : str or sequence, default None
468 Column label for index column(s). If None is given (default) and
469 `index` is True, then the index names are used.
470 A sequence should be given if the DataFrame uses MultiIndex.
471 chunksize : int, optional
472 Specify the number of rows in each batch to be written at a time.
473 By default, all rows will be written at once.
474 dtype : dict or scalar, optional
475 Specifying the datatype for columns. If a dictionary is used, the
476 keys should be the column names and the values should be the
477 SQLAlchemy types or strings for the sqlite3 legacy mode. If a
478 scalar is provided, it will be applied to all columns.
479 method : {None, 'multi', callable}, optional
480 Controls the SQL insertion clause used:
481
482 * None : Uses standard SQL ``INSERT`` clause (one per row).

Callers 1

to_sqlMethod · 0.90

Calls 4

delayedFunction · 0.90
tokenizeFunction · 0.90
_extra_depsFunction · 0.85
to_delayedMethod · 0.45

Tested by

no test coverage detected