PostgresOSM.import_data

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

Import tabular data into the database being connected.

See also [SQL-P-DD-1] and [SQL-P-DD-2].

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

  • table_name (str) – name of a table

  • schema_name (str) – name of a schema, defaults to '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 to replace existing table, defaults to False

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

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

  • method (str or None or typing.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 or int) – whether to print relevant information in console as the function runs, defaults to False

  • kwargs – optional parameters of pandas.DataFrame.to_sql

See the example for the method .read_sql_query().