I am trying to load data rows in postgres in a csv-like structure using the copy_from command (function to use the copy command in postgres). My data is separated by commas (and unfortunately, since I am not the owner of the data, I cannot just change the delimiter). I encounter a problem when I try to load a string that matters in quotation marks containing a comma (i.e., this comma should not be treated as a delimiter).
For example, this data row is beautiful:
",Madrid,SN,,SEN,,,SN,173,157"
This data row is small:
","Dominican, Republic of",MC,,YUO,,,MC,65,162",
Some codes:
conn = get_psycopg_conn()
cur = conn.cursor()
_io_buffer.seek(0)
cur.copy_from(_io_buffer, str(table_name), sep=',', null='', columns=column_names)
conn.commit()