Learn how Neon compares to Aurora Serverless v2 - TL;DR: faster cold starts, responsive autoscaling, 80% lower costs
Docs/Migrate to Neon/Import from CSV

Import data from CSV

This topic describes how to import data into a Neon database table from a CSV file.

The instructions require a working installation of psql. The psql client is the native command-line client for Postgres. It provides an interactive session for sending commands to Postgres. For more information about psql, refer to the psql reference, in the PostgreSQL Documentation.

The following example uses the ready-to-use neondb database that is created with your Neon project, a table named customer, and a data file named customer.csv. Data is loaded from the customer.csv file into the customer table.

  1. Connect to the neondb database using psql. For example:

    psql postgresql://[user]:[password]@[neon_hostname]/[dbname]

    note

    For more information about connecting to Neon with psql, see Connect with psql.

  2. Create the customer table.

    CREATE TABLE customer (
      id SERIAL,
      first_name VARCHAR(50),
      last_name VARCHAR(50),
      email VARCHAR(255),
      PRIMARY KEY (id)
    )

    tip

    You can also create tables using the SQL Editor in the Neon Console. See Query with Neon's SQL Editor.

  3. Prepare a customer.csv file with the following data:

    First Name,Last Name,Email
    1,Casey,Smith,casey.smith@example.com
    2,Sally,Jones,sally.jones@example.com
  4. From your psql prompt, load the data from the customer.csv file using the \copy option.

    \copy customer FROM '/path/to/customer.csv' DELIMITER ',' CSV HEADER

    If the command runs successfully, it returns the number of records copied to the database:

    COPY 2

    For more information about the \copy option, refer to the psql reference, in the PostgreSQL Documentation.

Need help?

Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more details, see Getting Support.

Last updated on

Was this page helpful?