COPY FROM statement
COPY FROM is used to import data from a file into a table by reading from the file 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.
The syntax for COPY FROM is as follows:
Two parameters need to be specified in the syntax:
- table_name: the table that will receive data from the file.
- file_path: a link to the file location accessible from the server.
First, you should create a CSV file and store it on your local computer. Here, we make a file called “feature2.csv” that stores features with its version.
You can use the syntax below for importing the file to the server:
Next, import the file to the server using the above syntax as shown below:
If it’s successfully imported, you will get the following result:
The file has been successfully uploaded to the server ✅. Now, connect to the Oxla server using the command below:
If you get the output below, you are currently in the Oxla environment.
Before creating a table, check for duplicate tables with the statement below:
In return, you will retrieve a list of existing tables in the Oxla.
Ensure you are not creating duplicate tables.
We need to create a table to retrieve the data from the CSV file. Here we will create a “featurelisttable” table. Using the same data type as described in the file is recommended.
Now, copy “feature2.csv” by executing the COPY FROM query below:
You will get the following successful result:
To verify that the data was imported correctly from the server, retrieve all the data using the SELECT statement:
You will have the same data in the table as in the CSV file.