I need to insert bunch of lines in Postgres table from python script and am using an advice to use copy_from for performance purpose.
import io
data_io = io.StringIO()
# here I have a loop which is omitted for simplicity
data_io.write("""%s\t%s\n""" % (115, 500))
DB = sql.DB()
DB._db_cur.copy_from(data_io, "temp_prices", columns=('id', 'price'))
In my code I am using a few loops to populate 'data' with values, above is an example.
But the table 'temp_prices' is empty and no errors were thrown
I know the data I needed is written into data_io, because I can see it when using:
print (data_io.getvalue())
What am I doing wrong?