COPY TO statement
COPY TO STDOUT
Overview
The COPY TO STDOUT
command is used to export data directly from a table to the client. This approach allows for data transfer by sending the data directly to the client, eliminating the need for server-side file operations.
Syntax
The basic syntax for using COPY TO STDOUT
is:
Parameters:
table_name
: The table from which the data will be exported.stdout
: Indicates that the data will be sent to the standard output (client application).
- Format: Only .csv is supported
- Delimiter: For CSV format, the default delimiter is a comma (,)
- Delimiter: For CSV format, the default delimiter is a comma (,)
Example
Step 1. Create the Table
- Create the table and insert some data into it.
- Upon successful creation, you should see the output below:
Step 2. Start the Export Operation
- Run the
COPY TO STDOUT
command to export the data from thebook_inventory
table:
- You will get the output with the table values, which you can use to create or copy into a CSV file: