Overview
TheCOPY FROM STDIN
command imports data directly from the client into a table. It simplifies the copy process by eliminating the need to transfer files to the server.
Syntax
The syntax for this function is as follows:Parameters
table_name
: table where the data will be importedstdin
: data coming from the standard input (client application)
,
.
Additional Options
1. Listing Column Names You can specify the columns into which the data should be imported.FROM stdin
to customize the import process.
Examples
Importing Data Manually
- Ensure the table exists in your database. If it doesn’t, create one using the following command:
- Initiate the import operation by running the following command:
- You will be prompted to enter your data. There will be a message as shown below:
-
Paste the data directly from your CSV file into the prompt:
IMPORT 0
at the end of the line.
To end the import process, for Unix-like systems press Ctrl + D.
- Verify the imported data by querying the table in a following way:
Direct CSV File Import
Use the following steps to import a CSV file directly into your Oxla instance. This method bypasses the need to manually enter data by reading the file and importing it directly into Oxla. After launching thepsql
client application and creating the film
table, download the film-dataset.csv file and execute the following query:
- Replace
table_name
with your target table name - Replace
/path/to/file
with the full path to your CSV file - Use
HEADER
if your CSV file includes column headers
Importing Data Using cat
Method
Ensure your dataset is in a valid CSV format. After creating a table using psql
, please follow the following steps:
- Type
\q
followed byEnter
to exitpsql
- Import the CSV File:
COPY
command.