Export Data to a CSV file
Overview
Exporting data from Oxla to a CSV file can be accomplished using the COPY TO
command. This guide outlines the methods for exporting data, including specifying delimiters, handling headers and controlling null value representation.
Syntax
The syntax for this function is as follows:
COPY table_name (column_name) TO {'file_path' | STDOUT}
WITH (option, …);
Parameters
table_name
: existing table from which the data will be exportedcolumn_name
: optionally list of columns to be exported. If omitted, all columns are exportedTO
: destination for the exported datafile_path
: path to the CSV file where the data will be writtenSTDOUT
: exports the data to the standard output stream
option
: available options below- FORMAT: output format (currently only CSV is supported)
- DELIMITER: delimiter character represented as single quote string literal (By default, this function uses commas as the delimiter)
- NULL: string to use for representing NULL values (e.g. NULL ‘unknown’)
- HEADER: boolean value indicating whether to include a header row with column names (values can be
TRUE
orFALSE
, with default set toFALSE
) - Endpoint: provide object-based storage credentials
Examples
Exporting Data via STDOUT
These example demonstrates how to export data from the file table to a CSV file named film_export.csv
, including a header row and using a semicolon as the delimiter.
1. Creating a table
Ensure that the table exists in your Oxla instance. If the table does not exist, create one using the following command:
2. Inserting Data
3. Executing the Export Command
- Replace
table_name
with your target table (e.g. film) - Replace
file_path
with the full path where the data will be written - Use
HEADER
to include a header row with column names
4. Verifying Export
Now let’s check the contents of film_export.csv
to ensure the data has been successfully exported
Exporting Data to Cloud Storage
To export data to an object storage from an Oxla table, you can use the COPY TO
command with object storage credentials. This command allows you to transfer data to a cloud storage services like AWS S3, Google Cloud Storage or Azure Blob Storage directly from your Oxla instance.
object storage
:AWS_CRED
,AZURE_CRED
orGCS_CRED
(depending on your provider)object_storage_credentials
: for accessing your cloud storage
You need to provide Provider-Specific credentials to authenticate access to your files. Use the following authentication parameters to access your cloud storage
AWS S3 Bucket
aws_region
: AWS region associated with the storage servicekey_id
: key identifier for authenticationaccess_key
: access key for authenticationendpoint_url
: URL endpoint for the storage service
NULL
values will be represented as ‘unknown’ as specified in the NULL
optionGoogle Cloud Storage
<path_to_credentials>
: path to JSON credentials file<json_credentials_string>
: contents of the GCS’s credentials file
Azure Blob Storage
tenant_id
: tenant identifier representing your organization’s identity in Azureclient_id
: client identifier used for authenticationclient_secret
: secret identifier acting as a password for authentication.