Back to Saving Tables

In Memory Tables · Saving Tables · Practice Question

Save a Table to a CSV File

Sign in to track your progress

Question

Given a table t, save it to a CSV file.

For example:

t:([] sym:`AAPL`MSFT`GOOG; price:185.25 410.1 142.8)

Solution

save `:t.csv

Explanation

save writes a global variable to disk, inferring the file format from the extension in the path — a .csv extension writes a comma-separated file, while other extensions (or none) write q's own binary format.

The leading colon in `:t.csv marks it as a file path rather than a plain symbol (a relative path, so the file is written to q's current working directory), and the filename itself (without the extension) must match the name of the variable being saved — t.csv saves the variable t. The resulting CSV includes a header row with the table's column names.