0

I have a text file which contains val1

And my table in PostgesSql is in format

val1 | val2 | val3 | ...

Edited : When I tried writing the command from here, Following error is shown.

Thanks in advance.

  • https://stackoverflow.com/questions/5233321/how-to-load-data-from-a-text-file-in-a-postgresql-database/21361964 – Luuk Feb 16 '20 at 13:47
  • An error is thrown. I edited the post and it is elaborated their. – Khondoker I. Islam Feb 16 '20 at 15:29
  • What do you not understand about `relation "mytable" does not exist` ? It does mean that you will have to create the table in postgresql yourself, before trying to import data. – Luuk Feb 16 '20 at 15:34
  • After that, I can then write this command and follow that link? – Khondoker I. Islam Feb 16 '20 at 15:48
  • Maybe look at this link, it works better: https://stackoverflow.com/questions/60250167/invalid-input-syntax-for-type-integer-in-postgresql#comment106572054_60250167 (only change tablename, and you use different delimiter...) – Luuk Feb 16 '20 at 15:54
  • Okay, I got what you are trying to mean. `Copy [the name of the table(the name of the column)] from 'path'`. I tried it, now new error is showing, error `could not open file "C:\Users\User\Downloads\your desired name.txt" 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` – Khondoker I. Islam Feb 16 '20 at 16:50
  • Try: `type myinput.csv | psql -d mytest -c "COPY mytable(myfiel1, myfield2, myfield3) FROM STDIN DELIMITER ';' CSV ;"` (replace all parts starting with `my` with their correct names. – Luuk Feb 16 '20 at 16:59
  • `Syntax Error at or near "type"` – Khondoker I. Islam Feb 16 '20 at 17:23
  • Than i am sorry to say that i cannot help you any more, because there is not enough info on my side to do so..... – Luuk Feb 16 '20 at 17:27

1 Answers1

0

There is a drop option in a table, there import the .txt file in the drop-down options with corresponding column name. Later refresh the table, then view it. Walah, you got table exactly as your .txt file. Thank You.