Using COPY FROM STDIN with list of lists as input #816
Replies: 1 comment
-
I don't think that avoid to use write_row but using CSV instead avoid so many bottleneck. So I would start simple, with That would be concise, like: with psycopg.connect(conn_str) as c:
cursor = c.cursor()
with cursor.copy(copy_query) as copy:
for row in rows:
copy.write_row(row) If you decide to use CSV and |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi All,
I have been trying to ingest some data to my db using COPY FROM but I am having trouble figuring out how to use it with Python lists. I just want to make sure I do not hit any bottlenecks with unnecessary loops - hence I'd rather not use copy.write_row() either.
I was able to convert the list of rows (list of lists) convert to a CSV like stream using the code below, but it seems like a lot of overhead though. In this example the list of lists is actually a list of pyodbc.Row objects, but that is on me I guess. I am only looking for a conversion between list of lists or list of tuples to ingest using COPY FROM STDIN.
Is there a better, more concise way of transforming a list of lists to a format which then can be fed to COPY FROM STDIN? I have read the API docs and the Using Copy From and Copy To as well but I did not see any examples that would help me achieve this.
Thank you very much in advance!
Beta Was this translation helpful? Give feedback.
All reactions