d6tstack
d6tstack copied to clipboard
Error while inserting a list/array object existing in a Dataframe Column to a Postgresql table column
Proving an example to replicate this issue: Consider the following Pandas Dataframe called my_data: | id | coordinates | | 01| [50.1, 68.2] | |02| [52.2, 67.9] |
and consider the following postgresql table definition
CREATE TABLE coordinates ( id int2, coordinates int8range );
Now, even if you cast this dataframe column to the type object
my_data['coordinates'] = my_data['coordinates'].astype(object)
the following insert operation throws an error:
d6tstack.utils.pd_to_psql(my_table, db, table, schema if_exists='replace')
The Error log is: BadCopyFileFormat: extra data after last expected column
The same insert operation works with dataframe.to_sql functionality provided by psycopg2
You need to add sep='\t' to the call.
d6tstack.utils.pd_to_psql(df, str(engine.url), table_name, if_exists='append',sep='\t')