Overview
COPY FROM statement is used to import data from a file into a table by reading from the file’s content directly. When using the COPY FROM, each field in the file is inserted sequentially into the specified column.
The file must be accessible and able to be read and written to
Syntax
The syntax for THECOPY FROM is as follows:
table_name: the table that will receive the data from the filefile_path: the link to the file location accessible from the server
Example
Creating CSV Files
Firstly, you should create a CSV file and store it on your local computer. Here, we make a file called “feature2.csv” that stores information about features with their versions:create a table, 1.0 modify a table, 1.2 drop a table, 2.2 rename a table, 2.0
Importing Files from Local to Server
You can use the syntax and the example presented below for importing the file to the server:Connecting to Oxla Server
Now that the file has been successfully uploaded to the server, you need to connect to Oxla using the command below:Creating a Table
Once you proceed to table creation stage, firstly it’s worth checking for duplicate tables, by executing the statement below:featurelist table:
Copying the CSV File Into the Table
Now, you can copy the “feature2.csv” by executing theCOPY FROM query, as shown below:
Retrieving the Table
To verify that the data was imported correctly from the server, you can retrieve all the data using theSELECT statement: