How to import CSV file data into a PostgreSQL table?

前端 未结 19 2315
再見小時候
再見小時候 2020-11-22 02:14

How can I write a stored procedure that imports data from a CSV file and populates the table?

19条回答
  •  梦如初夏
    2020-11-22 03:17

    Take a look at this short article.


    Solution paraphrased here:

    Create your table:

    CREATE TABLE zip_codes 
    (ZIP char(5), LATITUDE double precision, LONGITUDE double precision, 
    CITY varchar, STATE char(2), COUNTY varchar, ZIP_CLASS varchar);
    

    Copy data from your CSV file to the table:

    COPY zip_codes FROM '/path/to/csv/ZIP_CODES.txt' WITH (FORMAT csv);
    

提交回复
热议问题