Skip to content

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

OptionDescription
-t, --table=TABLE_NAMETarget table name
-d, --data=DATA_FILECSV file to import
-s, --server=SERVERServer IP address (default: 127.0.0.1)
-P, --port=PORTServer port (default: 5656)
-u, --user=USERUsername (default: SYS)
-p, --password=PASSWORDUser password (default: MANAGER)
-HTreat the first CSV row as a header and exclude it from ingestion
-CCreate the table if missing (with -H, use header values as column names)
-m, --mode=MODEImport mode: append (default) or replace
-a, --atimeInclude _ARRIVAL_TIME
-F, --dateformat=DATEFORMATDate format for datetime columns
-l, --log=LOG_FILEExecution log file
-b, --bad=BAD_FILEBad file for failed import rows
-I, --silentRun without banner or status output

Basic Usage

Specify the table and filename.

csvimport -t table_name -d data.csv

You can also use positional arguments without options, in either order.

csvimport table_name data.csv
csvimport data.csv table_name

Header Handling

Treat the first CSV row as a header and exclude it from the data.

csvimport -t table_name -d data.csv -H

Automatic 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 -H

All 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 replace

Specifying a Server Connection

csvimport -s 192.168.0.10 -P 5656 -u SYS -p MANAGER \
    -t sensor_data -d data.csv

csvexport

Export Machbase table data to a CSV file.

Options

OptionDescription
-t, --table=TABLE_NAMETable to export
-d, --data=DATA_FILEOutput CSV filename
-s, --server=SERVERServer IP address (default: 127.0.0.1)
-P, --port=PORTServer port (default: 5656)
-u, --user=USERUsername (default: SYS)
-p, --password=PASSWORDUser password (default: MANAGER)
-HWrite column names as the CSV header
-a, --atimeInclude _ARRIVAL_TIME
-F, --dateformat=DATEFORMATDate format for datetime columns
-l, --log=LOG_FILEExecution log file
-I, --silentRun without banner or status output

Basic Usage

csvexport -t table_name -d output.csv

You can also use positional arguments without options.

csvexport table_name output.csv
csvexport output.csv table_name

Exporting with a Header

Write column names as the first row (header) of the CSV file.

csvexport -t table_name -d output.csv -H

Exporting _ARRIVAL_TIME

csvexport -t table_name -d output.csv -a

Examples

# 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 -a
Last updated on