# Importing a CSV file into a dataset, filter it by date, then into a postgresql database

**URL:** <https://forum.inductiveautomation.com/t/importing-a-csv-file-into-a-dataset-filter-it-by-date-then-into-a-postgresql-database/17643>\
**Category:** Ignition\
**Tags:** scripting, database, ignition79\
**Created:** [April 9, 2018, 5:16pm UTC](https://forum.inductiveautomation.com/t/importing-a-csv-file-into-a-dataset-filter-it-by-date-then-into-a-postgresql-database/17643 "2018-04-09T17:16:19Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [April 9, 2018, 6:49pm UTC](https://forum.inductiveautomation.com/t/importing-a-csv-file-into-a-dataset-filter-it-by-date-then-into-a-postgresql-database/17643/4 "2018-04-09T18:49:36Z")

</div>

Rather than reading the entire file into the dataset I would use .next() to read the file line by line, evaluate if the date is within your parameters, and if so append to a dataset. After the file is parsed, convert the dataset to PyDataSet and use a for loop to run system.db.runPrepUpdate for each record. Here are some good resources:

[Exporting and Importing a CSV](https://docs.inductiveautomation.com/display/DOC79/Exporting+and+Importing+a+CSV)

[Inserting from dataset to database](http://forum.inductiveautomation.com/t/insert-dataset-into-sql-table/11557)

---

_[View the full topic](https://forum.inductiveautomation.com/t/importing-a-csv-file-into-a-dataset-filter-it-by-date-then-into-a-postgresql-database/17643)._
