Thursday, May 14, 2020

Re: Inserting data from a text file is not working for Postgres database

Try to give complete path of file and try again
Thank you,
Abhijit 

On Thu, 14 May, 2020, 10:27 AM Ram, <ram.mullapudi@gmail.com> wrote:
 Hi,

We are trying to insert the data from a text file 'some_category_list.txt'' into a table in Postgres database using the highlighted query in our functions.py

file = open(str(a)+'_category_list.txt', 'r')
file_content = file.read()
print(file_content)
file.close()
from django.db import connection
cursor = connection.cursor()
query = "COPY pages_rim_ls_categories FROM '{0}_category_list.txt' WITH DELIMITER AS '|'".format(str(a))
cursor.execute(query)


and we are getting this error

django.db.utils.OperationalError: could not open file "some_category_list.txt" for reading: No such file or directory
 
HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy.

Note: We used below query in the past using MySQL and it worked fine with that.

query = "LOAD DATA LOCAL INFILE 'some_category_list.txt' INTO TABLE pages_rim_ls_categories FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n' "

We are wondering what we are missing. Could someone help here to verify this?

Best regards
~Ram



 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BOi5F2P8Oy-gOUWC54imqcNvdmHw3LuC%3DuKkR5Xzq_w3HXjjA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2BOx31O8zOzhoyXyVoncDVSB5nWZU49%3DFgT49htrYhhwuWd19w%40mail.gmail.com.

No comments:

Post a Comment