I have the following table in Postgres:
Column | Type | Modifiers
------------+-----------------------------+-----------
customer | text |
feature | character varying(255) |
values | character varying[] |
updated_ts | timestamp without time zone |
And I'm trying to write the following pandas DataFrame
customer feature values updated_ts
0 A B [red, black] 2019-01-15 00:00:00
1 A B [blue, green] 2019-01-16 00:00:00
using the following code:
import psycopg2
...
sio = BytesIO()
sio.write(df.to_csv(header=False, index=False, sep='\t', quoting=csv.QUOTE_NONE))
sio.seek(0)
with connection.cursor() as cursor:
cursor.copy_from(file=sio, table=table, columns=df.columns, sep='\t', null='')
connection.commit()
But I'm getting the following error:
DataError('malformed array literal: "[\'red\', \'black\']"\nDETAIL: "[" must introduce explicitly-specified array dimensions.\nCONTEXT: COPY test_features_values, line 1, column values: "[\'red\', \'black\']"\n',)
How do I write it correctly?