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 imported into the database.

  • table_name (str) – Name of the table.

  • schema_name (str | None) – Name of the schema; if schema_name=None (default), it defaults to DEFAULT_SCHEMA (i.e. 'public').

  • if_exists (str) – Action to take if the table already exists. Options are 'replace', 'append' or 'fail' (default).

  • force_replace (bool) – Whether to force replace an existing table; defaults to False.

  • chunk_size (int | None) – 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': Passes 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 include the index as a column in the table.

  • confirmation_required (bool) – Whether to prompt for confirmation before proceeding; defaults to True.

  • verbose (bool | int) – Whether to print relevant information to the console; defaults to False.

  • kwargs – [Optional] Additional parameters for the method pandas.DataFrame.to_sql().

See also