Skip to content

export ​

Command: export
Category: Data Tools
Status: Production Ready

Description ​

Export table or view data to CSV, Excel, or JSON files. This is the complementary command to import, which loads data into tables.

Syntax ​

bash
hana-cli export [options]

Aliases ​

  • exp
  • downloadData
  • downloaddata

Command Diagram ​

Parameters ​

Positional Arguments ​

None.

Options ​

OptionAliasTypeDefaultDescription
--table-tstring-Source table or view name.
--schema-sstring**CURRENT_SCHEMA**Source schema name.
--output-ostring-Output file path. If omitted, a timestamped filename is generated.
--format-fstringcsvExport format. Choices: csv, excel, json.
--where-wstring-WHERE clause for filtering rows (without the WHERE keyword).
--limit-lnumber-Maximum number of rows to export. Defaults to --maxRows when unset.
--orderby--obstring-ORDER BY clause for sorting (without the ORDER BY keyword).
--columns-cstring*Comma-separated list of columns to export.
--delimiter-dstring,CSV delimiter character.
--includeHeaders--ihbooleantrueInclude header row in CSV export.
--nullValue--nvstring''Value to use for NULL/empty cells in CSV/Excel output.
--maxRows--mrnumber1000000Maximum rows allowed (used when --limit is not set).
--timeout--tonumber3600Operation timeout in seconds.
--profile-pstring-CDS profile for connections.

Connection Parameters ​

OptionAliasTypeDefaultDescription
--admin-abooleanfalseConnect via admin (default-env-admin.json).
--conn-string-Connection filename to override default-env.json.

Troubleshooting ​

OptionAliasTypeDefaultDescription
--disableVerbose--quietbooleanfalseDisable verbose output for scripting.
--debug-dbooleanfalseDebug hana-cli with detailed intermediate output.

Special Default Values ​

TokenResolves ToDescription
**CURRENT_SCHEMA**Current user's schemaUsed as default for --schema.
*All columnsUsed when --columns is not provided.

Output Formats ​

CSV Export ​

  • Standard comma-separated values format
  • First row contains column headers (configurable with --includeHeaders)
  • NULL values appear as empty cells or a custom value (with --nullValue)

Excel Export ​

  • Modern .xlsx format (Office Open XML)
  • Automatic column width adjustment
  • Data types preserved (numbers, dates, text)

JSON Export ​

  • JSON array of objects
  • Best for complex data structures and programmatic processing

Interactive Mode ​

In interactive mode, you are prompted for:

ParameterRequiredPromptedNotes
tableYesAlwaysSource table or view.
schemaNoAlwaysDefaults to current schema if omitted.
outputYesAlwaysFile path to write.
formatYesAlwaysSelect csv/excel/json.
whereNoSkippedUse --where to filter rows.
limitNoSkippedUse --limit to cap rows.
orderbyNoSkippedUse --orderby to sort results.
columnsNoSkippedUse --columns to select columns.
delimiterNoSkippedUse --delimiter for CSV.
includeHeadersNoSkippedUse --includeHeaders to toggle headers.
nullValueNoSkippedUse --nullValue for NULL replacement.
maxRowsNoSkippedUse --maxRows to cap rows.
timeoutNoSkippedUse --timeout to cap runtime.
profileNoAlwaysOptional CDS profile.

Examples ​

bash
hana-cli export --table myTable --format csv

Additional Examples ​

bash
# Excel export with column selection
hana-cli export -t EMPLOYEES -o ./output/staff.xlsx -f excel -c EMPLOYEE_ID,NAME,EMAIL,HIRE_DATE

# Export with WHERE clause
hana-cli export -t SALES -o ./output/2024_sales.csv -w "YEAR = 2024 AND STATUS = 'COMPLETED'"

# JSON export with ordering
hana-cli export -t PRODUCTS -o ./output/products.json -f json --orderby "PRICE DESC"

# Export with row limit
hana-cli export -t LARGE_TABLE -o ./output/sample.csv -l 1000

# CSV with custom delimiter
hana-cli export -t DATA -o ./output/data.tsv -d '\t'

# Export from a specific schema
hana-cli export -t CUSTOMERS -s SALES_DB -o ./output/customers.csv

Workflow Examples ​

Backup and Restore Workflow ​

bash
# Export current production data
hana-cli export -t CRITICAL_TABLE -s PRODUCTION -o ./backup/critical_$(date +%Y%m%d).csv -f excel

# Import into a target environment
hana-cli import -n ./backup/critical_20260215.csv -t CRITICAL_TABLE -s STAGING -m name

Large Dataset Export Strategy ​

bash
# First batch
hana-cli export -t BIG_TABLE -o ./batch1.csv -l 100000

# Subsequent batches with filtering
hana-cli export -t BIG_TABLE -o ./batch2.csv -l 100000 -w "ID > 100000"

Frequently Asked Questions ​

Can I export views? ​

Yes, the export command works with both tables and views.

bash
hana-cli export -t SCHEMA.VIEW_NAME -o output.csv

What is the maximum export size? ​

The export is limited by available disk space and the --maxRows setting (default: 1,000,000 rows). Use batching for larger exports.

What happens to NULL values? ​

  • By default, NULL appears as empty cells in CSV/Excel.
  • Use --nullValue to customize the replacement.
  • JSON preserves NULL as JSON null.

Performance Considerations ​

FactorRecommendation
Large datasetsUse --limit to test, then export in batches.
Specific columnsUse --columns to reduce file size and export time.
Long-running exportsIncrease --timeout for millions of rows.
File format choiceJSON is larger; use CSV for bulk data.
Filtering efficiencyApply WHERE clause at database level.

Error Handling ​

ErrorCauseSolution
Table not foundTable doesn't exist or wrong schemaVerify table name and schema via hana-cli inspectTable -t TABLE.
Column not foundColumn doesn't existCheck column names with hana-cli inspectTable -t SCHEMA.TABLE.
File write failedPermission denied or invalid pathEnsure output directory exists and is writable.
Timeout exceededQuery took too longUse WHERE clause to filter, increase --timeout.
Invalid formatUnsupported format choiceUse csv, excel, or json.

Tips and Best Practices ​

  1. Always test first: Use -l 100 to preview data before full export.
  2. Include timestamps: Add timestamps to filenames for version tracking.
  3. Choose format wisely:
    • CSV for data analysis tools
    • Excel for business users
    • JSON for APIs and web applications
  4. Validate before import: Check file integrity after export.
  5. Use schemas explicitly: Specify schema to avoid ambiguity.

See the Commands Reference for other commands in this category.

See Also ​