Skip to content

Instantly share code, notes, and snippets.

@pastcompute
Last active August 29, 2015 14:03
Show Gist options
  • Save pastcompute/b32f65f82c7889cdfa86 to your computer and use it in GitHub Desktop.
Save pastcompute/b32f65f82c7889cdfa86 to your computer and use it in GitHub Desktop.
Script to make a SQL table definition from CSV
echo "create table raw_data ( `head -1 raw_data.csv | sed -e 's/\?//g' -e 's/ /_/g' -e 's/,/ text,/g' -e 's/$/ text'`);" > raw_data.table.sql
echo "copy raw_data from '`pwd`/raw_data.csv' csv header;
echo "grant all privileges on table raw_data to seeu";
psql mydb < raw_data.table.sql
@pastcompute
Copy link
Author

Need to be postgres user to use copy which is annoying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment