Importing a CSV Into PostgreSQL Like a Pro

3 years ago | Postgres YouTube
Importing data into PostgreSQL can be time consuming and painful – unless you toss the GUI tools and use scripts.

USING HEAD

It all starts with using the head command in the shell in order to pull out the column names:

head -1 master_plan.csv

This will pop out the very first line of the CSV, which is typically the header row. I’m working with Cassini’s mission plan data, so this is what I see:

Now I just copy/paste that into VS Code and run a simple replacement using “Change all Occurrences” to build my create table statement.

The final step is to use the copy from command to pull data out of the CSV and into the database. There’s a whole lot more to this (like data types to use and creating an isolated schema) – just watch the video already!

Learn Postgres Using Data from NASA's Cassini Mission

I wrote a fun database tutorial using data from NASA's Cassini Mission. You get to load up your database with actual data from Saturn: A Curious Moon

  • Real data from Cassini
  • Search for traces of alien life (really)
Have some thoughts? You can always reply to this post (if you're receiving as a newsletter) or shoot me an email at rob@conery.io. If the conversation is a good one, I would love to add it here, with your permsission, of course. Otherwise, you can always take it to HackerNews.

There's More...

👹 The Wrath of the Junior Developer

There are a lot of opinions about AI, whether it helps or hinders our coding process and our team in general. Many are concerned that junior devs will be the ones impacted the most.

Following Your Imagination

I learned to play ice hockey when I was 11 and, as a kid from Southern California, it wasn't easy. I learned how to skate and how to play the game at the same time, all while going through a massive growth spurt. My sister once called me a "baby giraffe on a frozen lake". Nice.

It wasn't what you said, but how you said it

I make videos for a living and I swear: each one is an adventure. You would think I would have a system down by now but, as it turns out, each video is a unique thing that demands it's own type of story telling.