Importing data into PostgreSQL can be time consuming and painful – unless you toss the GUI tools and use scripts.

Importing data into PostgreSQL can be time consuming and painful – unless you toss the GUI tools and use scripts. I get into this in SQL in Orbit (which I launched last month) but I thought I’d share the technique with everyone.

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
Code language: Bash (bash)

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:

Pulling the fields out of our CSV

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!

April 17, 2020

This is part 3 of a series of posts I’m writing for Friendo, a web person who wants to get their hands a lot dirtier with Node and Postgres.

Postgres For Those Who Can’t Even, Part 3 – In The Real World

February 5, 2020

Getting up to speed with Postgres and Node can be daunting but in this post I’ll dive into how you can easily work with both – including JSON document storage… in Postgres!

Postgres For Those Who Can’t Even, Part 2 – Working with Node and JSON

January 24, 2020

Just yesterday I was talking to a friend about Postgres (not uncommon) and he said something that I found shocking: I can’t even with Postgres, I know JACK SQUAT

PostgreSQL For Those Who Can’t Even, Part 1
>