'extra data after last expected column while getting list values from csv file
I am trying to save list values from my csv file in my postgres database. Have tried multiple ways but this copy_from seemed to be working a little but when I run it as follow
with open("test8.csv") as f:
next(f)
cursor.copy_from(f,"details1",sep=",",)
I get his error
extra data after last expected column
CONTEXT: COPY details1, line 1: "9955,https://products/WMDCATHIEYWH2WPPK_0.jpg,"['Hair', '..."
as you can see my last value is a list
The following is my connection and table details
conn = psycopg2.connect(database="db",user='admin', password='admin',host='localhost', port='5432')
conn.autocommit = True
cursor = conn.cursor()
sql = '''CREATE TABLE DETAILS1(id int NOT NULL,url char(20),\
labels text[]);'''
cursor.execute(sql)
Another important note is that I have tried it using the following method as well
from pathlib import Path
print(Path.cwd())
sql2 = f'''COPY DETAILS1(id,url,labels) FROM '{Path.cwd()}\\test8.csv'
DELIMITER ','
CSV HEADER;'''
but it kept giving me this error
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.
Interestingly.... \copy also does not work while the file is there
Solution for any of the problems will be much appreciated Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
