Two copy command syntaxes were tried, and the corresponding errors are shown below:
1.
COPY smartphones(brand_name, model, price, rating, has_5g, has_nfc, has_ir_blaster, processor_brand, num_cores, processor_speed,battery_capacity, fast_charging_available, fast_charging, ram_capacity, internal_memory, screen_size, refresh_rate, num_rear_cameras, num_front_cameras, os, primary_camera_rear, primary_camera_front, extended_memory_available, extended_upto, resolution_width, resolution_height)from ‘C:Program FilesPostgreSQL16datadata_copysmartphones.csv’ DELIMITER ‘,’ CSV HEADER ;
ERROR: column "brand_name" of relation "smartphones" does not exist [It exist in Reality]
2.
COPY smartphones from ‘C:Program FilesPostgreSQL16datadata_copysmartphones.csv’ DELIMITER ‘,’ CSV HEADER ;
ERROR: extra data after last expected column
CONTEXT: COPY smartphones, line 2: "oneplus,OnePlus 11 5G,54999,89, TRUE,TRUE,FALSE,snapdragon,8,3.2,5000,1,100,12,256,6.7,120,3,1,androi…"
I failed to retrieve a CSV file with 26 columns in PostgreSQL. The error "INTERNAL SERVER ERROR: ‘columns’ when trying to import a csv file through pgAdmin4" was encountered when the import function was used similarly. I was unable to locate any appropriate solution online, so is there a way to solve this issue? If so, could you please offer your suggestion?
2
Answers
COPY is unable to generate a table for you, so it won't function. That must be completed before you can copy it.
This problem now begs a new query. Is there a method for a table to be generated automatically in PostgreSQL when using the copy or import functions?
Either you aren’t connected to the right database / looking at the right schema or some such, or (and this is most likely), you created the table quoted and the column is called "Brand_Name" with capitals or something like that. If you (or the tools you use) quote identifiers you probably want to quote them all the time.
Google "sql case folding" for details.
This is almost certainly because the file is not a correct CSV file. Check the line carefully there will be an unquoted value with a comma in it.