Nasrul Hazim Bin Mohamad

PostgreSQL – Import data from CSV

Mar
10

You CSV file similar to the following:

"a",1
"b",2
"c",3
"d",4

The SQL:

COPY table_name(col1,col2) FROM 'C:UsersPublicDocumentsCSVdata.csv' WITH DELIMITER AS ',' CSV QUOTE AS '"';

References:

  1. http://forums.enterprisedb.com/posts/list/2819.page
  2. http://dba.stackexchange.com/questions/18821/how-to-import-a-csv-file-into-a-postgresql-database-using-copy
  3. http://stackoverflow.com/questions/2987433/how-to-import-csv-file-data-into-a-postgres-table
  4. http://www.postgresql.org/docs/9.1/static/sql-copy.html
  5. http://stackoverflow.com/questions/10079682/copy-function-in-postgresql

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

8 + thirteen =