Skip to content

Instantly share code, notes, and snippets.

@robconery
Created September 28, 2023 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robconery/f8697847e0ca5055deceb989a693c8e1 to your computer and use it in GitHub Desktop.
Save robconery/f8697847e0ca5055deceb989a693c8e1 to your computer and use it in GitHub Desktop.
SQL Extraction Import

When importing data into Postgres from a CSV, it's imperative that you do not try to alter the data - do that by explicitly transforming the data later on.

That means we need to import everything as text, because that's the core string type in Postgres (as opposed to varchar etc).

To create our schema and table:

create schema csvs;
create table csvs.master_plan(
  start_time_utc text,
  duration text,
  date text,
  team text,
  spass_type text,
  target text,
  request_name text,
  library_definition text,
  title text,
  description text
);

Copying data from a CSV into our new table:

copy csvs.master_plan 
from '[Absolute path to]/csvs/master_plan.csv'
delimiter ',' header csv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment