Thanks.
csv is more than a flat file. It is a convention (not a standard) how to describe a record set in plain text.
I download my csv from some website. It goes to my download directory, from where I pick it up with my file picker dialog.
The text table “TYPE_A_CSV” may be linked to a previously imported text file file “A_Import.csv” in the database directory.
SET TABLE "TYPE_A_CSV" SOURCE OFF;
disconnects the old text file.
Then I replace the old text file with the new one picked up from my download directory and reconnect the text table with its text file before running the INSERT command. What the INSERT command actually does is encoded in the view.
All the details depend completely on the csv file and the view decoding this specific type of csv,
- how text is encoded,
- how dates, times, decimals are formatted,
- the order of columns,
- columns to skip, columns to add
- the field separator,
- the text separator,
- if there is a header row or not,
- if duplicate records should be avoided.
The proper setup of the text table splits the text rows into columns of type VARCHAR. If a column has ISO dates, you may declare them as date. The time column in my sample could be declared as time. If a column has point decimals with no currency symbol nor thousands separator, it may be declared as decimal.
In this sample, I declared every column as VARCHAR and let the view convert all the text. The view does most of the import job.
How to do the same manually without any macro.
- Close the database (disconnect text table).
- Copy the newly downloaded csv to “A_Import.csv” in the database directory.
- Open the database.
- Copy the icon of the view.
- Select the data table icon and paste.
- Confirm the import dialog without further adjustments (the view takes care of the column order).
Having some other website as data source from where you download differently structured csv files, you have to create another text table “TYPE_B_CSV” with another source file “B_Import.csv”, another view “VIEW_TYPE_B” converting the text file to your data table format, create another import routine with different constant declarations for the file picker and for the table names. All the data go to the same data table, so they are comparable to each other.
The embedded HSQLDB is documented here: Chapter 9. SQL Syntax
Text file chapter: Chapter 6. Text Tables