Varan Download Varan →
Varan › CSV to PostgreSQL

CSV to PostgreSQL: connect and query a CSV in one statement

You have a table in PostgreSQL and a CSV on your desktop, and you need them together. Here's how to connect a CSV to PostgreSQL and JOIN or query it in a single SQL statement — without importing the file or standing up a pipeline.

A PostgreSQL orders table joined to two CSV files in one query — run locally on DuckDB.

Connect and query, or import? They're different

Two different goals hide behind "CSV to PostgreSQL," and the right answer depends on which you mean:

If you want the second one — connect a CSV to PostgreSQL and query it in place — you don't need an import at all.

The usual (painful) options

What you actually want is to treat the file as a table and write a normal join.

The clean way: a local cross-source engine

Varan runs an in-process DuckDB engine that can read your PostgreSQL database and your CSV files at the same time, so a single JOIN spans both — read-only, on your machine, with nothing written back.

Step by step

  1. Connect PostgreSQL. Add your database with read-only credentials.
  2. Open the CSV. Drag the file in — Varan exposes it as a queryable table (and scans it for anomalies on open).
  3. Write one query. Join the PostgreSQL table to the CSV table like any normal SQL:
SELECT c.name, c.country, s.tier,
       COUNT(o.id)  AS orders,
       SUM(o.total) AS revenue
FROM   customers  c                       -- customers.csv on disk
JOIN   pg__orders o ON o.customer_id = c.id  -- PostgreSQL table
JOIN   segments   s ON s.customer_id = c.id  -- segments.csv on disk
GROUP BY c.name, c.country, s.tier
ORDER BY revenue DESC;
  1. Run it. The engine pulls only what it needs from PostgreSQL and reads the CSV directly — one joined result, in milliseconds.

Do this with your own file

Varan is a desktop app for macOS and Windows — free during the beta.

Download Varan →

FAQ

How do I connect a CSV to PostgreSQL without importing it?

Point Varan at your PostgreSQL database and open the CSV — it becomes a queryable table, so you can read or JOIN it against Postgres at query time. Nothing is loaded into the database and nothing is written back. If you instead want the CSV to become a Postgres table, that's an import with COPY/\copy.

Can you JOIN a CSV to a PostgreSQL table without importing it?

Yes — Varan reads the file at query time and joins it to PostgreSQL live, so there's no import and no staging table.

What about joining a CSV to MySQL, or two databases together?

Same approach — see how to join tables from different databases.

How is this different from a normal SQL client?

A normal client connects to one database and can't see a file as a table. See Varan vs DBeaver and Varan vs TablePlus.