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

后端 未结 4 854
無奈伤痛
無奈伤痛 2020-12-14 17:06

I have a file like (CSV file):

value1|value2|value2....

value1|value2|value2....

value1|value2|value2....

value1|value2|value2....

and w

4条回答
  •  生来不讨喜
    2020-12-14 17:23

    There's Pgloader that uses the aforementioned COPY command and which can load data from csv (and MySQL, SQLite and dBase). It's also using separate threads for reading and copying data, so it's quite fast (interestingly enough, it got written from Python to Common Lisp and got a 20 to 30x speed gain, see blog post).

    To load the csv file one needs to write a little configuration file, like

    LOAD CSV  
      FROM 'path/to/file.csv' (x, y, a, b, c, d)  
      INTO postgresql:///pgloader?csv (a, b, d, c)  
      …
    

提交回复
热议问题