Skip to content

Instantly share code, notes, and snippets.

@karlclement
Forked from jboesch/pg_import_csv_to_heroku.sh
Created November 30, 2017 14:39
Show Gist options
  • Select an option

  • Save karlclement/3f6cead3f3258a1e4ea1b9d240299ece to your computer and use it in GitHub Desktop.

Select an option

Save karlclement/3f6cead3f3258a1e4ea1b9d240299ece to your computer and use it in GitHub Desktop.

Revisions

  1. @jboesch jboesch revised this gist May 18, 2013. 2 changed files with 17 additions and 26 deletions.
    26 changes: 0 additions & 26 deletions pg_import_csv_to_heroku
    Original file line number Diff line number Diff line change
    @@ -1,26 +0,0 @@
    You have your csv data and it looks like so... It's in a file named "my_data.csv" and we want to import it into a table named "my_things".

    "1", "Something", "0.50", "2013-05-05 10:00:00"
    "2", "Another thing", "1.50", "2013-06-05 10:30:00"

    Now you want to import it, go to the command line and type:

    ```sql
    PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
    ```

    Voila! It's impoted. Now if you want to wipe it out and import a fresh one, you would do this:

    ```
    heroku pg:psql
    ```

    ```
    TRUNCATE table my_things;
    ```

    Now re-do the PGPASSWORD command above:

    ```
    PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
    ```
    17 changes: 17 additions & 0 deletions pg_import_csv_to_heroku.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # You have your csv data and it looks like so... It's in a file named "my_data.csv" and we want to import it into a table named "my_things".

    "1", "Something", "0.50", "2013-05-05 10:00:00"
    "2", "Another thing", "1.50", "2013-06-05 10:30:00"

    # Now you want to import it, go to the command line and type:

    $ PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"

    # Voila! It's impoted. Now if you want to wipe it out and import a fresh one, you would do this:

    $ heroku pg:psql
    $ TRUNCATE table my_things;

    Now re-do the PGPASSWORD command above:

    $ PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
  2. @jboesch jboesch revised this gist May 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pg_import_csv_to_heroku
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ You have your csv data and it looks like so... It's in a file named "my_data.csv

    Now you want to import it, go to the command line and type:

    ```
    ```sql
    PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
    ```

  3. @jboesch jboesch created this gist May 18, 2013.
    26 changes: 26 additions & 0 deletions pg_import_csv_to_heroku
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    You have your csv data and it looks like so... It's in a file named "my_data.csv" and we want to import it into a table named "my_things".

    "1", "Something", "0.50", "2013-05-05 10:00:00"
    "2", "Another thing", "1.50", "2013-06-05 10:30:00"

    Now you want to import it, go to the command line and type:

    ```
    PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
    ```

    Voila! It's impoted. Now if you want to wipe it out and import a fresh one, you would do this:

    ```
    heroku pg:psql
    ```

    ```
    TRUNCATE table my_things;
    ```

    Now re-do the PGPASSWORD command above:

    ```
    PGPASSWORD=PWHERE psql -h HOSTHERE -U USERHERE DBNAMEHERE -c "\copy my_things FROM 'my_data.csv' WITH CSV;"
    ```