COPY FROM
**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.
Syntax
The syntax for THE COPY FROM
is as follows:
where:
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:
After a successful import, you will get the following result:
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:
Once you successfully connected to an Oxla server, you should get a similar output:
Creating a Table
Once you proceed to table creation stage, firstly it’s worth checking for duplicate tables, by executing the statement below:
In return, you will retrieve a list of all existing tables in Oxla:
After that, you need to create a table to retrieve the data from the CSV file. Here, we will create a featurelist
table:
Copying the CSV File Into the Table
Now, you can copy the “feature2.csv” by executing the COPY 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 the SELECT
statement:
Now you should have the same data in the table as in the CSV file.