Overview
When you export data from a table to a CSV file using theCOPY TO
command, you can include or skip the header. Oxla provides three options for handling headers: HEADER OFF
, HEADER ON
, and HEADER MATCH
.
Syntax
The syntax forCOPY TO
with HEADER
is as follows:
table_name
: The table containing the data to be exported.file_path
: The CSV file location where the data will be saved.Header_Syntax
: The specified header options.
Header Options
- HEADER OFF
This option is a default behaviour if
HEADER
is not provided.- HEADER ON
Examples
First, create a “personal_details” table.COPY TO
with different header options:
Case #1: HEADER OFF
Please ensure that the directory where you save the file has a write permissions.
- Run the query below to export the table.
- You will get the following output, indicating that the table has successfully exported to the CSV file.
- The data in the table is copied directly to the
personalinfo
file without considering the first row as a header.
To include headers, use the
HEADER ON
option.Case #2: HEADER ON
- Run the query below to export the table.
- You will get a successful output below.
- In this case, the header from the table will be included in the CSV file.