Skip to content

Fix pgAdmin Import CSV – Missing Data or Encoding Errors

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Fix pgAdmin Import CSV. We cover key concepts, practical examples, and best practices.

You right‑click a table in pgAdmin, select Import/Export, pick your CSV file, and hit OK. Half the rows come through with garbled text, NULLs where there should be numbers, or a generic "ERROR: invalid input syntax for type integer".

Wrong ❌

-- pgAdmin auto-detected delimiter as comma, but your CSV uses semicolons
COPY users(id, name, email, signup_date)
FROM '/tmp/users.csv'
DELIMITER ',' CSV HEADER;

Your CSV actually looks like:

id;name;email;signup_date
1;Alice;alice@example.com;2024-01-15
2;Bob;bob@example.com;2024-01-16

The comma delimiter splits each field wrong, mangling every row.

Using the Import/Export dialog:

  1. Right‑click the target table → Import/Export…
  2. Toggle to Import
  3. Browse to your CSV file
  4. Set Delimiter to ; (or \t for TSV)
  5. Quote — usually "
  6. Escape — usually "
  7. Header — YES
  8. Encoding — UTF8 (or match your file, e.g. WIN1252)
  9. Click OK

Or using COPY with explicit options:

COPY users(id, name, email, signup_date)
FROM '/tmp/users.csv'
DELIMITER ';' CSV HEADER ENCODING 'UTF8';
COPY 2
-- two rows imported successfully

Root Cause

pgAdmin applies sensible defaults (DELIMITER ',', ENCODING 'UTF8'), but real‑world CSVs vary wildly: semicolons, tabs, BOM headers, Windows line endings, or mixed quoting. When the delimiter doesn't match, PostgreSQL can't parse the file.

Prevention

  • Inspect the first few lines of your CSV with head -n5 file.csv or file file.csv to detect encoding.
  • Always preview the delimiter in the Import/Export dialog before running.
  • For dirty CSVs, pre‑process with sed or a Python script to normalise separators and quoting.
  • Test with a 5‑row sample before importing the full file.

Common Mistakes with import csv

  1. Misunderstanding that String is [Char] with poor performance for large text operations
  2. Using foldl instead of foldl' causing stack overflow on large lists
  3. Forgetting deriving (Show, Eq) on custom data types needed for debugging

These mistakes appear frequently in real-world PGADMIN code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

**Q: Why does pgAdmin show "Permission denied" for my CSV?**

A: pgAdmin runs as the postgres user on the server. Place the CSV in /tmp or a directory readable by postgres, or use the pgAdmin client‑side import option.

**Q: Can I import without a header row?**

A: Yes — set Header to NO. Columns are mapped positionally.

**Q: What if my CSV has NULL values?**

A: Use the NULL field in the dialog (default \N). If your CSV uses empty strings, leave it blank; for explicit NULL, set the NULL string to NULL.

**Q: How do I handle large CSVs (>100 MB)?**

A: Use psql with \copy instead of pgAdmin. The web interface can time out on large uploads.


Master data import workflows with the [DodaTech PostgreSQL Data Loading course](https://dodatech.com/courses/postgresql-data-loading).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro