databasepostgresqlcsv

How to load data from a text file in a PostgreSQL database?


I have a file like (CSV file):

value1|value2|value2....

value1|value2|value2....

value1|value2|value2....

value1|value2|value2....

and would like to load these data into a postgresql table.


Solution

  • The slightly modified version of COPY below worked better for me, where I specify the CSV format. This format treats backslash characters in text without any fuss. The default format is the somewhat quirky TEXT.

    COPY myTable FROM '/path/to/file/on/server' ( FORMAT CSV, DELIMITER('|') );