python - Adding string with new line characters in a file to upload to an SQL UTF8 database -
i've discovered \copy command upload csv/tsv files table. it's convenient method because have large amount of data load @ same time.
my problem have text load , of them contain \n characters. because generate utf-8 text files, recognized new line characters , can't loaded in database. there way encode them, using python function, create file upload ?
to replace \n i've used python str replace method when creating tsv file.
i replace \n \\\\n. method gives me \\n in tsv files and, because postgresql insertion file interpret special characters, \\n stored \n in database.
so :
my_usable_string = my_string.replace("\n", "\\\\n")
Comments
Post a Comment