16.4.4 csvimport / csvexport
csvimport and csvexport are simple CSV import/export wrappers. They simplify the CSV options of
machloader; options not listed below can be used as with machloader.
csvimport
Import a CSV file into a Machbase table.
Options
| Option | Description |
|---|---|
-t, --table=TABLE_NAME | Target table name |
-d, --data=DATA_FILE | CSV file to import |
-s, --server=SERVER | Server IP address (default: 127.0.0.1) |
-P, --port=PORT | Server port (default: 5656) |
-u, --user=USER | Username (default: SYS) |
-p, --password=PASSWORD | User password (default: MANAGER) |
-H | Treat the first CSV row as a header and exclude it from ingestion |
-C | Create the table if missing (with -H, use header values as column names) |
-m, --mode=MODE | Import mode: append (default) or replace |
-a, --atime | Include _ARRIVAL_TIME |
-F, --dateformat=DATEFORMAT | Date format for datetime columns |
-l, --log=LOG_FILE | Execution log file |
-b, --bad=BAD_FILE | Bad file for failed import rows |
-I, --silent | Run without banner or status output |
Basic Usage
Specify the table and filename.
csvimport -t table_name -d data.csvYou can also use positional arguments without options, in either order.
csvimport table_name data.csv
csvimport data.csv table_nameHeader Handling
Treat the first CSV row as a header and exclude it from the data.
csvimport -t table_name -d data.csv -HAutomatic Table Creation
Create the table automatically if it does not exist.
# Generate column names c0, c1, ...
csvimport -t table_name -d data.csv -C
# Use CSV header values as column names
csvimport -t table_name -d data.csv -C -HAll automatically created columns have type varchar(32767).
Replace Mode
Delete existing data and refill the table from the CSV file.
csvimport -t table_name -d data.csv -m replaceSpecifying a Server Connection
csvimport -s 192.168.0.10 -P 5656 -u SYS -p MANAGER \
-t sensor_data -d data.csvcsvexport
Export Machbase table data to a CSV file.
Options
| Option | Description |
|---|---|
-t, --table=TABLE_NAME | Table to export |
-d, --data=DATA_FILE | Output CSV filename |
-s, --server=SERVER | Server IP address (default: 127.0.0.1) |
-P, --port=PORT | Server port (default: 5656) |
-u, --user=USER | Username (default: SYS) |
-p, --password=PASSWORD | User password (default: MANAGER) |
-H | Write column names as the CSV header |
-a, --atime | Include _ARRIVAL_TIME |
-F, --dateformat=DATEFORMAT | Date format for datetime columns |
-l, --log=LOG_FILE | Execution log file |
-I, --silent | Run without banner or status output |
Basic Usage
csvexport -t table_name -d output.csvYou can also use positional arguments without options.
csvexport table_name output.csv
csvexport output.csv table_nameExporting with a Header
Write column names as the first row (header) of the CSV file.
csvexport -t table_name -d output.csv -HExporting _ARRIVAL_TIME
csvexport -t table_name -d output.csv -aExamples
# Basic import
csvimport -t sensor_data -d sensor_20240101.csv
# Import CSV with a header
csvimport -t sensor_data -d sensor_20240101.csv -H
# Export all data, including a header
csvexport -t sensor_data -d export_20240101.csv -H
# Import with log files
csvimport -t sensor_data -d data.csv -H \
-l import.log -b import.bad
# Export from a remote server
csvexport -s 192.168.0.10 -P 5656 -u SYS -p MANAGER \
-t sensor_data -d remote_export.csv -H -aLast updated on