Search code examples
databasecsv

Viewing a very large CSV file?


I have a very large 3.5 GB CSV file that I'd like to be able to read, sort through and filter for results based on various inputs. I'm pretty sure I can just import it to a MySQL database and go from there, but is there any program or online tool available that involves simply uploading the CSV and the rest is automatic?


Solution

  • You could try PostgreSQL 9.1+ and its file_fdw (File Foreign Data Wrapper) which would pretend that the CSV file is a table. If you replaced the CSV file with another CSV file of the same name, then you would see the new info immediately in the database.

    You can improve performance by using a materialized view (PG 9.3+) which essentially creates a real database table from the CSV data. You could use pgAgent to refresh the materialized view on a schedule.

    Another alternative would be to use the COPY statement:

    /* the columns in this table are the same as the columns in your csv: */
    create table if not exists my_csv (
      some_field text, ...
    );
    
    /* COPY appends, so truncate the table if loading fresh data again: */
    truncate table my_csv;
    
    /* 
    you need to be a postgres superuser to use COPY 
    use psql \copy if you can't be superuser 
    put the csv file in /srv/vendor-name/
    */
    
    copy 
      my_csv 
    from 
      '/srv/vendor-name/my.csv'
    with (
      format csv
    );