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.
orders table joined to two CSV files in one query — run locally on DuckDB.Two different goals hide behind "CSV to PostgreSQL," and the right answer depends on which you mean:
COPY / \copy, and it's the right call when the file is your source of truth going forward.If you want the second one — connect a CSV to PostgreSQL and query it in place — you don't need an import at all.
\copy into a staging table — load the CSV into PostgreSQL first, then join. Works, but you own a throwaway table and the data is a stale copy.file_fdw foreign data wrapper — powerful, but needs server-side setup, superuser rights, and a fixed file path on the database host.What you actually want is to treat the file as a table and write a normal join.
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.
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;
Varan is a desktop app for macOS and Windows — free during the beta.
Download Varan →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.
Yes — Varan reads the file at query time and joins it to PostgreSQL live, so there's no import and no staging table.
Same approach — see how to join tables from different databases.
A normal client connects to one database and can't see a file as a table. See Varan vs DBeaver and Varan vs TablePlus.