Back in September 2025, David Fetter asked on IRC, about a tool to quickly load CSV to database. One that would require minimal configuration, will try to figure out as much as possible on its own.
I thought that it would be great idea. Plus, I'm trying to learn more JavaScript / Node, so figured I can try.
Work and life intervened, and I couldn't get to it.
In the mean time I also read a lot of praise for some AI tools for quickly starting projects, or adding functionality, or learning new stuff. So, I decided to try.
Used Claude to make the basics, and then worked to add more tests and functionality.
Long story short, the tool is here.
It does what David wanted – works as simply as possible. Assuming you have your environment configured, you can just:
=$ pg_csv_loader some_file.csv
And it will figure out delimiter, quote character, column names, datatypes, and will load it to default database – which works just like normal psql
Tested it on couple different csv files, and it seems to work. It also handled PostgreSQL csv logs, which are often problematic as they use literal new line characters, which is causing problems for some parsers.
I don't claim that I wrote it, but I did extend tests, and datatype detection, so I guess I have some partial credit 🙂
Hope you'll find it useful.
This is one of those things that every DBA knows should be easy but there’s always cases — like the multiple lines problem with Postgres CSV logging — that cause problems.
There’s also https://github.com/dimitri/pgloader
I wish there was one definitive, maintained tool for this.
Nice, but lacking the DB url first argument of psql – if that was there I’d love to switch away from the not very nice csvsql tool from csvkit.
why not psql and COPY?
“`
psql “connection_string” -c “\copy (SELECT * FROM sales WHERE year = 2023) TO ‘filtered_data.csv’ WITH CSV HEADER”
“`
@Colin:
Last time I checked pgloader couldn’t make table based on what it sees in the csv.
@Viktor:
I always disliked url as a way to provide connection details. Hence it didn’t even occur to me to handle this. Even in psql it’s (in my opinion) more of an afterthought – there is no –url option, for example.
@Phill:
Not sure how copying data *from* pg to csv relates to what Claude & me wrote – this is for the othner direction. And while I know that COPY can load csv, it can’t make table based on csv data.