Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to import/export data using CSV in PostgreSQL

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 731
    Comment on it

    To export a table data from Postgres database to a CSV file, use the "COPY to" command. You can create a CSV file using MS-Excel or directly create a file from the command.

    Syntax: COPY (SELECT * FROM table_name) to E'C:\Users\main\Documents\file.csv' csv

    Example: COPY (SELECT * FROM productcategory) to E'C:\Users\dinesh\Documents\prodcat.csv' csv

    To import data from a CSV file to Postgres table , use the "COPY from" command.

    Syntax: COPY table_name FROM E'C:\Users\main\Documents\file.csv' WITH Delimiter ',' Null '' csv;

    Example: COPY product_product FROM E'C:\Users\dinesh\Documents\product.csv' WITH Delimiter ',' Null '' csv;

    Note: Use double backslash for the file path and E'' fr the path string. You can use any format but that I will cover later.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: