> Full Neon documentation index: https://neon.com/docs/llms.txt

# How do I import data from a CSV file into my Neon database?

Use psql with \copy from your local machine, or pgloader for large or messy CSVs.

Create the target table in Neon, then run `\copy` from a `psql` session connected to your database. `\copy` streams the CSV from your local filesystem over the existing connection, so it doesn't need access to the server's filesystem. For larger or messier CSVs, `pgloader` handles encoding, type coercion, and parallel loading. See [Import data from CSV](https://neon.com/docs/import/import-from-csv).

## Import a CSV with psql

First, create the destination table. Unless you list columns in the `\copy` command, the table columns must match the CSV columns in number and order:

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

You can run this from the [Neon SQL Editor](https://neon.com/docs/get-started/query-with-neon-sql-editor) or from `psql`.

Then connect with `psql` and load the file. To get the connection command, click **Connect** in the Neon Console and pick `psql` from the drop-down menu.

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

On success, psql prints the number of rows loaded:

```text
COPY 1842
```

`CSV HEADER` tells psql to skip the first row of the file. Drop `HEADER` if your CSV has no header line.

### Load specific columns

If the CSV has fewer columns than the table, or a different column order, list the columns in CSV order:

```bash
\copy customer (first_name, last_name, email) FROM '/path/to/customer.csv' DELIMITER ',' CSV HEADER;
```

## When to use pgloader

`pgloader` is a third-party tool. Use it when:

- The CSV is millions of rows and you want parallel loading
- Source columns need type casts or date parsing
- The file has encoding issues, embedded quotes, or inconsistent rows
- You're loading from MySQL, SQLite, or another database rather than a CSV file

You write a small config file that describes the source, target, and any transformations, and pgloader runs the load and reports rows that fail. See the [pgloader documentation](https://pgloader.readthedocs.io/) for syntax.

**Note: The SQL Editor does not support \copy**

`\copy` is a psql client-side meta-command. It runs in psql itself, not on the Postgres server. The Neon SQL Editor in the Console supports many meta-commands (`\dt`, `\d`, `\l`), but not `\copy`. Use psql, a Postgres GUI like DBeaver or pgAdmin, or a script in your language of choice.

**Tip: COPY FROM STDIN works too**

The server-side `COPY ... FROM '/path/to/file.csv'` form reads from the Postgres server's filesystem, which isn't accessible on Neon. `COPY ... FROM STDIN` works fine over a connection and is what `\copy` uses under the hood. Both psql `\copy` and `COPY FROM STDIN` from a driver stream the data from the client.

> **Walk through a full CSV import**
>
> Step-by-step example: connect, create the table, prep the CSV, and load with psql.
>
> [Read the CSV import guide](https://neon.com/docs/import/import-from-csv)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/faqs/import-csv-into-database"}` to https://feedback.neon.tech/ (no auth required).
