> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# /export/records/tofiles

```
URL: http://<db.host>:<db.port>/export/records/tofiles
```

Export records from a table to files. All tables can be exported, in full or
partial (see *columns\_to\_export* and *columns\_to\_skip*). Additional filtering
can be applied when using export table with expression through SQL. Default
destination is KIFS, though other storage types (Azure, S3, GCS, and HDFS) are
supported through *datasink\_name*; see
[/create/datasink](/content/api/rest/create_datasink_rest).

Server's local file system is not supported.  Default file format is delimited
text. See options for different file types and different options for each file
type.  Table is saved to a single file if within max file size limits (may vary
depending on datasink type).  If not, then table is split into multiple files;
these may be smaller than the max size limit.

All filenames created are returned in the response.

## Input Parameter Description

<ParamField body="table_name" type="string" />

<ParamField body="filepath" type="string">
  Path to data export target.  If input parameter *filepath* has a file extension, it is read as the name of a file. If input parameter *filepath* is a directory, then the source table name with a random UUID appended will be used as the name of each exported file, all written to that directory. If filepath is a filename, then all exported files will have a random UUID appended to the given name.  In either case, the target directory specified or implied must exist.  The names of all exported files are returned in the response.
</ParamField>

<ParamField body="options" type="map of string to strings">
  Optional parameters.

  The default value is an empty map ( \{} ).

  <Expandable title="options">
    <ParamField body="batch_size">
      Number of records to be exported as a batch.

      The default value is `1000000`.
    </ParamField>

    <ParamField body="column_formats">
      For each source column specified, applies the column-property-bound format.  Currently supported column properties include date, time, and datetime. The parameter value must be formatted as a JSON string of maps of column names to maps of column properties to their corresponding column formats, e.g., '\{ "order\_date" : \{ "date" : "%Y.%m.%d" }, "order\_time" : \{ "time" : "%H:%M:%S" } }'.

      See *default\_column\_formats* for valid format syntax.
    </ParamField>

    <ParamField body="columns_to_export">
      Specifies a comma-delimited list of columns from the source table to export, written to the output file in the order they are given.

      Column names can be provided, in which case the target file will use those names as the column headers as well.

      Alternatively, column numbers can be specified--discretely or as a range.  For example, a value of '5,7,1..3' will write values from the fifth column in the source table into the first column in the target file, from the seventh column in the source table into the second column in the target file, and from the first through third columns in the source table into the third through fifth columns in the target file.

      Mutually exclusive with *columns\_to\_skip*.
    </ParamField>

    <ParamField body="columns_to_skip">
      Comma-separated list of column names or column numbers to not export.  All columns in the source table not specified will be written to the target file in the order they appear in the table definition.  Mutually exclusive with *columns\_to\_export*.
    </ParamField>

    <ParamField body="datasink_name">
      Datasink name, created using [/create/datasink](/content/api/rest/create_datasink_rest).
    </ParamField>

    <ParamField body="default_column_formats">
      Specifies the default format to use to write data. Currently supported column properties include date, time, and datetime.  This default column-property-bound format can be overridden by specifying a column property and format for a given source column in *column\_formats*. For each specified annotation, the format will apply to all columns with that annotation unless custom *column\_formats* for that annotation are specified.

      The parameter value must be formatted as a JSON string that is a map of column properties to their respective column formats, e.g., '\{ "date" : "%Y.%m.%d", "time" : "%H:%M:%S" }'.  Column formats are specified as a string of control characters and plain text. The supported control characters are 'Y', 'm', 'd', 'H', 'M', 'S', and 's', which follow the Linux 'strptime()' specification, as well as 's', which specifies seconds and fractional seconds (though the fractional component will be truncated past milliseconds).

      Formats for the 'date' annotation must include the 'Y', 'm', and 'd' control characters. Formats for the 'time' annotation must include the 'H', 'M', and either 'S' or 's' (but not both) control characters. Formats for the 'datetime' annotation meet both the 'date' and 'time' control character requirements. For example, '\{"datetime" : "%m/%d/%Y %H:%M:%S" }' would be used to write text as "05/04/2000 12:12:11"
    </ParamField>

    <ParamField body="export_ddl">
      Save DDL to a separate file.

      The default value is `false`.
    </ParamField>

    <ParamField body="file_extension">
      Extension to give the export file.

      The default value is `.csv`.
    </ParamField>

    <ParamField body="file_type">
      Specifies the file format to use when exporting data.

      The default value is `delimited_text`.

      * **delimited\_text**: Delimited text file format; e.g., CSV, TSV, PSV, etc.
      * **parquet**
    </ParamField>

    <ParamField body="kinetica_header">
      Whether to include a Kinetica proprietary header. Will not be written if *text\_has\_header* is *false*.

      The default value is `false`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="kinetica_header_delimiter">
      If a Kinetica proprietary header is included, then specify a property separator. Different from column delimiter.

      The default value is `|`.
    </ParamField>

    <ParamField body="compression_type">
      File compression type. GZip can be applied to text and Parquet files.  Snappy can only be applied to Parquet files, and is the default compression for them.

      The supported values are:

      * uncompressed
      * snappy
      * gzip
    </ParamField>

    <ParamField body="single_file">
      Save records to a single file. This option may be ignored if file size exceeds internal file size limits (this limit will differ on different targets).

      The default value is `true`.

      The supported values are:

      * true
      * false
      * overwrite
    </ParamField>

    <ParamField body="single_file_max_size">
      Max file size (in MB) to allow saving to a single file. May be overridden by target limitations.

      The default value is ''.
    </ParamField>

    <ParamField body="text_delimiter">
      Specifies the character to write out to delimit field values and field names in the header (if present).

      For *delimited\_text* *file\_type* only.

      The default value is `,`.
    </ParamField>

    <ParamField body="text_has_header">
      Indicates whether to write out a header row.

      For *delimited\_text* *file\_type* only.

      The default value is `true`.

      The supported values are:

      * true
      * false
    </ParamField>

    <ParamField body="text_null_string">
      Specifies the character string that should be written out for the null value in the data.

      For *delimited\_text* *file\_type* only.

      The default value is `\N`.
    </ParamField>
  </Expandable>
</ParamField>

## Output Parameter Description

The Kinetica server embeds the endpoint response inside a standard response structure which contains status information and the actual response to the query.  Here is a description of the various fields of the wrapper:

<ResponseField name="status" type="String">
  'OK' or 'ERROR'
</ResponseField>

<ResponseField name="message" type="String">
  Empty if success or an error message
</ResponseField>

<ResponseField name="data_type" type="String">
  'export\_records\_to\_files\_response' or 'none' in case of an error
</ResponseField>

<ResponseField name="data" type="String">
  Empty string
</ResponseField>

<ResponseField name="data_str" type="JSON or String">
  This embedded JSON represents the result of the /export/records/tofiles endpoint:

  <Expandable title="data_str">
    <ResponseField name="table_name" type="string">
      Name of source table.
    </ResponseField>

    <ResponseField name="count_exported" type="long">
      Number of source table records exported.
    </ResponseField>

    <ResponseField name="count_skipped" type="long">
      Number of source table records skipped.
    </ResponseField>

    <ResponseField name="files" type="array of strings">
      Names of all exported files.
    </ResponseField>

    <ResponseField name="last_timestamp" type="long">
      Timestamp of last file scanned.
    </ResponseField>

    <ResponseField name="data_text" type="array of strings" />

    <ResponseField name="data_bytes" type="array of bytes" />

    <ResponseField name="info" type="map of string to strings">
      Additional information.
    </ResponseField>
  </Expandable>

  Empty string in case of an error.
</ResponseField>
