0

Summary

I failed to import CSV files into a table on PostgreSQL. Even though it says that the import was successfully completed, there's no rows created. How did this happen, and how can I fix this? Thank you.

Details

1. The CSV file I (failed to) imported, is like this 1. CSV file imported

| number | ticket     | category  | question                 | answer                | url            | note     |
|--------|------------|-----------|--------------------------|-----------------------|----------------|----------|
| 1      | #0000000   | Temp>123  | *confirming*             | Would you...?         | https:///....a | -        |
| 2      | #1234567   | AAA / BBB | "a" vs "b"               | If A, "a". If B, "b". | https:///....b | #0000000 |
| 3      | #1234567-2 | AAA>abc   | Can we do sth using "a"? | Yes, blah blah blah.  | https:///....b | -        |

And this is the table on PostgreSQL

  • numberr : numeric
  • ticketr : char
  • category : char[]
  • question : char
  • answer : char
  • url : char
  • note : char

2.\ The message after the import Even though it says that the import was "successfully completed" When I hit “More details” of the import pop up (3. Message - Completed) --command " "\\copy public.test (\"number\", ticket, category, question, answer, url, note) FROM '/Users/alice/Desktop/test.csv' DELIMITER ',' CSV HEADER ENCODING 'UTF8' QUOTE '\"' ESCAPE '''';""

3. The message when I made sure that the file was actually imported

  • When I click "Count Rows", it says "Table rows counted: 0"
  • I tried the following script in Query Tool of the table, and it shows no rows created
SELECT * FROM (table name)

For references

Screenshot

4. No row created / 1. CSV file imported / 2. Import Preference / 3. Message - Completed / 5. postgres_log

8
  • Please replace the links to images with text versions of the information. We also need me more information 1) The CSV file structure as text file, not shown in Excel. 2) The schema of the table you importing into. Commented May 2, 2021 at 15:44
  • Welcome to the SO community. Please take a few minuets to take the Tour and review the help section How to Ask. For useful information concerning images see images, Why not Upload Images Commented May 2, 2021 at 19:35
  • Hi @AdrianKlaver, thank you. I added the structure of the CSV file and table. If you need any other info, please let me know. Thank you! Commented May 3, 2021 at 9:29
  • Shouldn't SELECT * FROM (file name) be SELECT * FROM table_name? Are you sure you are looking at correct table? Are there data rows in /Users/hsaito/Desktop/test1.csv? Commented May 3, 2021 at 14:44
  • Hi Adiran, Apologies for the mistake. (Both of the table name and the file name are the same this time, so there should not have an impact here.) Yes, I chose the csv file in the file selector, so the file path should be fine. Commented May 3, 2021 at 14:54

3 Answers 3

1

After changing the name of a column from "number" to "consecutive", the error message showed up in Query Tool (not in Import/Export)

  1. Tried Query Tool instead of Import/Emport --> the situation didn’t change

  2. Changed the first column name from “number” to “constructive” in both csv and psql table --> the situation didn’t change

  3. Tried Query Tool copy public.test (consecutive, ticket, category, question, answer, url, note) FROM '/Users/alice/Desktop/test5.csv' DELIMITER ',' CSV HEADER ENCODING 'UTF8' QUOTE '"' ESCAPE '''';"" --> the situation didn’t change

  4. Tried Query Tool copy public.test (consecutive, ticket, category, question, answer, url, note) FROM '/Users/alice/Desktop/test5.csv' DELIMITER ',' CSV HEADER ENCODING 'UTF8' —>got error message ERROR: could not open file "/Users/alice/Desktop/test5.csv" for reading: Permission denied HINT: COPY FROM instructs the PostgreSQL server process to read a file. You may want a client-side facility such as psql's \copy. SQL state: 42501

Sign up to request clarification or add additional context in comments.

1 Comment

This was the actual issue actually. I copied the file in docker's mapped volume using root privileges and it changed the file permissions. When I changed the file folder / file permissions, it worked fine.
0

check columns settings in tab at 2. Import Preference image

right from options tab

there you should set columns order as in your file

also check more details at 3. Message - Cpmpleted

1 Comment

Hi Alan, thank you for your comment. I confirmed that the CSV file has columns that the PostgreSQL table has. And they're set in the same order. Thank you!
0

This is a file permission issue. Open a shell terminal, go to the directory where the data file is stored, and run chmod +rx * and retry loading the data file into your DB.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.