Update a CSV table in SQLite Studio

1.4k Views Asked by At

I have a bunch of CSVs that get updated locally on my computer every few days. I want to refresh them in SQLite Studio but I can't find out where to actually refresh. Is there an option to do this? The only way i've been able to refresh is to fully delete the table, and then re-import it under the same name (so the query still works). All of the CSVs and Sqlite Studio are local on my computer I am not running anything remote.

1

There are 1 best solutions below

5
On

CSV file is not linked in any way with SQLiteStudio. Once you import data to table, it is in table, not in CSV file. If you want to refresh contents of table with data from CSV files, then you need to do exactly what you already do, that is re-import.

An useful tool to make this repeatable task less clumsy is import() SQL function built in SQLiteStudio. You can easily delete old data and re-import new one in single execution:

delete from your_table;
select import('path/to/file.csv', 'CSV', 'your_table', 'UTF-8');

Of course you need to adjust your parameters. Also there can be 5th (optional) parameter specifying importing options, just like in Import Dialog. Quoting from User Manual (https://github.com/pawelsalawa/sqlitestudio/wiki/User_Manual#built-in-sql-functions):

charsets() Returns list of charsets supported by SQLiteStudio (to be used for example in arguments for import() function)

import_formats() Returns list of importing formats supported by SQLiteStudio (depends on import plugins being loaded)

import_options(format) Returns list of currently used importing settings for certain format (the format must be one of formats returned from import_formats()). Each setting in a separate line. Each line is a setting_name=setting_value

import(file, format, table, charset, options) Executes importing process using file for input, format for choosing import plugin (must be one of values returned from import_formats()). The import is done into the table. If table does not exists, it will be created. The charset is optional and must be one of values returned from charsets() (for example 'UTF-8'). It defaults to UTF-8. The options is optional and has to be in the same format as returned from import_options() (which is one option per line, each line is option_name=value), although it's okay to provide only a subset of options - then the rest of settings will remain.