Varan Join the beta →
Varan › How to join a CSV to PostgreSQL

How to join a CSV file to a PostgreSQL table in one query

You have a table in PostgreSQL and a CSV on your desktop, and you need them together. Here's how to JOIN them in a single SQL query — 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.

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 a local-first 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, Windows and Linux — free during the beta.

Request beta access →

FAQ

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.