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)
Import tabular data into a table.
See also [DBMS-PS-ID-1] and [DBMS-PS-ID-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; when
schema_name=None
(default), it defaults toDEFAULT_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 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 Callable) –
method for SQL insertion clause, defaults to
'multi'
None
: uses standard SQLINSERT
clause (one per row);'multi'
: pass multiple values in a singleINSERT
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 also
Examples for the method
pyhelpers.dbms.PostgreSQL.read_sql_query()
.