PostgreSQL.import_data

PostgreSQL.import_data(data, table_name, schema_name=None, if_exists='fail', force_replace=False, chunk_size=None, col_type=None, method='multi', index=False, confirmation_required=True, verbose=False, **kwargs)[source]

Import tabular data into a table.

See also [DBMS-PS-ID-1] and [DBMS-PS-ID-2].

Parameters:
  • data (pandas.DataFrame | pandas.io.parsers.TextFileReader | list | tuple) – tabular data to be dumped into a database

  • table_name (str) – name of a table

  • schema_name (str) – name of a schema; when schema_name=None (default), it defaults to DEFAULT_SCHEMA (i.e. 'public')

  • if_exists (str) – if the table already exists, to 'replace', 'append' or, by default, 'fail' and do nothing but raise a ValueError.

  • force_replace (bool) – whether to force replacing existing table, defaults to False

  • chunk_size (int | None) – the number of rows in each batch to be written at a time, defaults to None

  • col_type (dict | None) – data types for columns, defaults to None

  • method (str | None | Callable) –

    method for SQL insertion clause, defaults to 'multi'

    • None: uses standard SQL INSERT clause (one per row);

    • 'multi': pass multiple values in a single INSERT clause;

    • callable (e.g. PostgreSQL.psql_insert_copy) with signature (pd_table, conn, keys, data_iter).

  • index (bool) – whether to dump the index as a column

  • confirmation_required (bool) – whether to prompt a message for confirmation to proceed, defaults to True

  • verbose (bool | int) – whether to print relevant information in console as the function runs, defaults to False

  • kwargs – [optional] parameters of pandas.DataFrame.to_sql

See also